Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for different Java versions #8249

Closed
mnonnenmacher opened this issue Feb 9, 2024 · 16 comments
Closed

Improve support for different Java versions #8249

mnonnenmacher opened this issue Feb 9, 2024 · 16 comments
Labels
analyzer About the analyzer tool enhancement Issues that are considered to be enhancements

Comments

@mnonnenmacher
Copy link
Member

mnonnenmacher commented Feb 9, 2024

Currently the Docker image and the artifacts published to Maven Central are both built with Java 17. This can cause two kinds of issues:

  • Docker: As the Maven and Gradle analyzers are built into ORT and compiled with the same Java version, sometimes projects cannot be analyzed that require a different Java version. For example, the project could use a Gradle version that is not compatible with Java 17, or the project could require Java 21.
  • Maven Central: Projects that use ORT programmatically as a library, like the ORT workbench, must be compiled with at least the same Java version as the ORT artifacts. However, for the same reason as above it could be required to build those tools with a different Java version.

One approach to solve this would be to release the Docker images and the Maven Central artifacts with different variants for each of the Java LTS releases, currently relevant are Java 11, 17, and 21.

Another more complex approach would be to decouple the Maven and Gradle analyzers from ORT itself and release them as standalone tools, comparable to the python-inspector. These tools could then be released with a bundled JVM for the different Java versions.

Also see some related PRs and issues: #4948, #6311, #8027, #8242

@mnonnenmacher mnonnenmacher added the analyzer About the analyzer tool label Feb 9, 2024
@heliocastro
Copy link
Contributor

I can say decoupling Maven, and Gradle is the best suitable solution.

Explain what would be the alternatives and how this can become a nightmare:

1 - Multiple docker images with all LTS images.
Today we build docker itself with Temurin as base: FROM eclipse-temurin:$JAVA_VERSION-jdk-$UBUNTU_VERSION as base
This means that we will need to build base as standard image, and take care of java installs on later stage to avoid blowup the images with 3x all layers.
We would treat java as another independent layer. Maintenance will be hard as long we start to change base distro, as we have layers pointing out for the base. Example:
Today we have all build over Ubuntu 22.04, and python 3.10.x build for this.
We will have soon the new LTS from Ubuntu, So base image will be updated to 24.04, and then same python 3.10.x will be built over this one. Any older image referring to this python will be unstable, as will point originally to older base.
And not forgetting, we need rename the images for each version.
Resume:
maintenance complexity: Higher, size increase: High, effectiveness: medium

2 - Use SDKMAN for java
So, instead of multiple images, we use SDKMAN to install parallel Java sdk's and during process change the environment to select the required JDK.
It will slightly increase our build time for docker, but then will make multiple Java SDK's install easier and is future proof.
But then we now transfer to Ort how it will manage in runtime the switch for the specific JDK and I honestly can't tell if is a good idea or not since I don't know that Ort code at all. Maybe a runtime environment switch will be easier from the Ort point of view.
Resume:
maintenance complexity: Low, size increase: Medium, effectiveness: ?

@sschuberth sschuberth added the enhancement Issues that are considered to be enhancements label Feb 11, 2024
@sschuberth
Copy link
Member

I'm also thinking into the direction of simply installing multiple JDK versions in parallel in the Docker image, and finding a way to choose the JDK at runtime for the package manager implementations. At least for SBT that would work, as it's called as an external CLI tool. Also for Gradle projects that leverage the toolchains mechanism that should work. Not sure about Maven, though.

@mnonnenmacher
Copy link
Member Author

mnonnenmacher commented Feb 13, 2024

Not sure about Maven, though.

I'm not sure if have seen the issue with Maven projects so far, probably because it's more declarative than Gradle. Maybe it can happen if plugins are used the require a specific Java version, we at least load Wagon transport plugins.

@heliocastro

This comment has been minimized.

@sschuberth

This comment has been minimized.

@sschuberth
Copy link
Member

My current idea, at least for SBT for now, is to bootstrap the required JDK via https://github.com/foojayio/discoclient at ORT analyzer runtime.

@fb33
Copy link
Contributor

fb33 commented Mar 7, 2024

Hi,
Just a feedback with jdk21.
I have some projects with gradle 8.5 and jdk21, and of course with the current ORT docker image, the analyzer failed.
I make a quick (and naive) test, building in ORT image with jdk21 and run the analyzer.
=> there is no more issue, but the analyzer found no dependency !

I have also some projects with maven and jdk21, and there is no issue with them, all is fine.

@fb33

This comment has been minimized.

@sschuberth

This comment has been minimized.

@fb33
Copy link
Contributor

fb33 commented Mar 8, 2024

@sschuberth
here is a sample of gradle project on jdk21 with the results&logs of ORT
https://github.com/fb33/sample-gradle8.5-jdk21

hope this help.
regards

mnonnenmacher added a commit that referenced this issue Mar 12, 2024
Configure Gradle to build class files compatible with Java 11. This
allows to use the published ORT artifacts also in Projects that use Java
11. Previously, Java 17 was required.

The main use case for this is to build a Docker image with Java 11 to be
able to analyze Gradle projects that are not compatible with newer Java
versions.

Relates to #8249.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
mnonnenmacher added a commit that referenced this issue Mar 12, 2024
Configure Gradle to build class files compatible with Java 11. This
allows to use the published ORT artifacts also in Projects that use Java
11. Previously, Java 17 was required.

The main use case for this is to be able to build the Analyzer Docker
image for the ORT Server [1] with Java 11 which is required to analyze
Gradle projects that are not compatible with newer Java versions.

Relates to #8249.

[1]: https://github.com/eclipse-apoapsis/ort-server

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
mnonnenmacher added a commit that referenced this issue Mar 12, 2024
Configure Gradle to build class files compatible with Java 11. This
allows to use the published ORT artifacts also in Projects that use Java
11. Previously, Java 17 was required.

The main use case for this is to be able to build the Analyzer Docker
image for the ORT Server [1] with Java 11 which is required to analyze
Gradle projects that are not compatible with newer Java versions.

Relates to #8249.

[1]: https://github.com/eclipse-apoapsis/ort-server

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
sschuberth added a commit that referenced this issue Mar 13, 2024
The previous code was calling `JavaVersion.current()` at build time,
assuming that the Java version running Gradle is the same Java version
used for building ORT. This assumption makes it more difficult to built
ORT for different Java versions. Solve that by using Gradle's toolchains
mechanism [1] instead.

Choose Java 11 as the default for the new `javaLanguageVersion` property
to support analyzing older projects with ORT, also see [2].

[1]: https://docs.gradle.org/current/userguide/toolchains.html
[2]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Mar 14, 2024
The previous code was calling `JavaVersion.current()` at build time,
assuming that the Java version running Gradle is the same Java version
used for building ORT. This assumption makes it more difficult to build
ORT for different Java versions in the same environment. Solve that by
using Gradle's toolchains mechanism [1] instead.

Choose Java 11 as the default for the new `javaLanguageVersion` property
to support analyzing older projects with ORT, also see [2].

[1]: https://docs.gradle.org/current/userguide/toolchains.html
[2]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Mar 14, 2024
The previous code was calling `JavaVersion.current()` at build time,
assuming that the Java version running Gradle is the same Java version
used for building ORT. This assumption makes it more difficult to build
ORT for different Java versions in the same environment. Solve that by
using Gradle's toolchains mechanism [1] instead.

Choose Java 11 as the default for the new `javaLanguageVersion` property
to support analyzing older projects with ORT, also see [2].

[1]: https://docs.gradle.org/current/userguide/toolchains.html
[2]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 5, 2024
Note that `setJavaHome()` [1] set the Java home to "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 5, 2024
Note that `setJavaHome()` [1] set the Java home to "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 6, 2024
Note that `setJavaHome()` [1] set the Java home to "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 6, 2024
Note that `setJavaHome()` [1] sets the Java home "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 6, 2024
Note that `setJavaHome()` [1] sets the Java home "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 6, 2024
Note that `setJavaHome()` [1] sets the Java home "to use for the Gradle
process". However, as by default (unless toolchains are used [2]) "Gradle
will compile Java code to the language level of the JVM running Gradle"
[3], this will impact the Java target of the build.

See #8249 for context.

[1]: https://docs.gradle.org/current/javadoc/org/gradle/tooling/ConfigurableLauncher.html#setJavaHome(java.io.File)
[2]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:compiling_with_toolchain
[3]: https://docs.gradle.org/8.10/userguide/building_java_projects.html#sec:java_cross_compilation

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 13, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 18, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 18, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 18, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 18, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 19, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 19, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 19, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 19, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
@sschuberth
Copy link
Member

sschuberth commented Sep 20, 2024

Do you have any idea when you'll fix the usage of jdk21 for gradle and sbt project ?

@fb33 for Gradle it was basically fixed by #9127, for SBT it will be fixed by #9179. Both introduce package manager options to customize the JDK to use.

here is a sample of gradle project on jdk21 with the results&logs of ORT
https://github.com/fb33/sample-gradle8.5-jdk21

Could you yourself give #9179 a try on it?

@fb33
Copy link
Contributor

fb33 commented Sep 20, 2024

Hi @sschuberth

I have done some successful tests with ORT-32.1.0 👍

I don't know if I did it in the way you imagine, but here is what I done :

I built a special ORT docker image (with only tools for my stacks) in which I added open jdk 21.
In the ort.yml, I indicate the javaHome here :

    packageManagers:
      GradleInspector:
        options:
          javaHome: /usr/lib/jvm/java-21-openjdk-amd64

I override javaHome (the default one - 17, or the jdk21) on the fly according to the stack of projects being audited.

@sschuberth
Copy link
Member

I override javaHome (the default one - 17, or the jdk21) on the fly according to the stack of projects being audited.

Yes, that's a perfectly valid way to do it. If you can limit the number of required JDKs beforehand, you can add them to the Docker image and just configure the right Java home per ORT run. Alternatively, if you don't know which JDK will be required, you can let ORT bootstrap a JDK at runtime that matches the javaVersion option. If both javaHome and javaVersion are given, javaVersion takes precedence.

@fb33
Copy link
Contributor

fb33 commented Sep 20, 2024

Great ! I'll try the bootstrap method.
thanks for the advice !

and good job for this new feature ! 👏

sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 20, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 27, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 30, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Sep 30, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Oct 1, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit that referenced this issue Oct 3, 2024
As fcfab20 decoupled the Java version to use for analysis of Gradle
projects from the Java version running ORT, finally update the Java
version from 11 / 17 to 21. See [1] for context.

Also stop using the deprecated `Thread.id` in favor of `Thread.threadId()`
and ensure to run with Java 21 when generating completion scripts.

[1]: #8249

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
@sschuberth
Copy link
Member

@mnonnenmacher, do you think this can be closed now with the recent additions to customize the Java home / version?

@mnonnenmacher
Copy link
Member Author

@mnonnenmacher, do you think this can be closed now with the recent additions to customize the Java home / version?

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer About the analyzer tool enhancement Issues that are considered to be enhancements
Projects
None yet
Development

No branches or pull requests

4 participants