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

Use Gradle Toolchains for JVM projects to test on unsupported JDK versions #25787

Closed
sbrannen opened this issue Sep 18, 2020 · 3 comments
Closed
Assignees
Labels
type: task A general task
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Sep 18, 2020

Gradle 6.7 will introduce built-in support for Toolchains for JVM projects.

Once we upgrade to Gradle 6.7, we will should hopefully be able to replace the functionality in custom-java-home.gradle with the new built-in support.

Note from the Gradle team:

Toolchains and *Compatibility: the moment you use toolchain at the project level, sourceCompatibility and targetCompatibility from the project have a value derived from the toolchain. What you cannot do is overwrite that value. You can still overwrite it at the task level though.

@sbrannen sbrannen added the type: task A general task label Sep 18, 2020
@sbrannen sbrannen added this to the 5.x Backlog milestone Sep 18, 2020
@sbrannen sbrannen modified the milestones: 5.x Backlog, 5.3 GA Oct 16, 2020
@sbrannen
Copy link
Member Author

Depends on #25918.

@sbrannen sbrannen modified the milestones: 5.3 GA, 5.3.1 Oct 27, 2020
@jhoeller jhoeller modified the milestones: 5.3.1, 5.3.2 Nov 6, 2020
@jhoeller jhoeller modified the milestones: 5.3.2, 5.x Backlog Nov 27, 2020
@sbrannen
Copy link
Member Author

sbrannen commented Dec 4, 2020

Beginning with Gradle 6.8, it will also be possible to track the vendor and implementation of the JVM for caching purposes. See gradle/gradle#9102 (comment) for details.

@bclozel
Copy link
Member

bclozel commented Mar 12, 2021

Here's a proposal for introducing Gradle Toolchains in our build.

This changes two things:

  • the Concourse build now relies on a single CI image shipping all JDKs we want to test
  • we can now use the -PmainToolchain and -PtestToolchain project parameters to configure what to use

Gradle JVM Toolchain

This proposal is configuring Java, Kotlin and Groovy compilation with the following behavior:

Gradle Command Main Sources Compiled Tests Compiled + Run
./gradlew check JDK8 JDK8
./gradlew check -PmainToolChain=11 JDK11 JDK11
./gradlew check -PmainToolChain=8 -PtestToolchain=15 JDK8 JDK15

You can use that locally. If Gradle detects the required JDKs it will use them, otherwise Gradle will download the AdoptOpenJDK one automcatically. You can check which JDKs are detected on your host with

$ ./gradlew -q javaToolchains

This is rather flexible and allows to:

  1. Compile our artifacts as usual and test them using other JDK versions (basically, how developer experience Spring)
  2. Compile and test our artifacts with recent JDK version to check for compatibility issues

Concourse build

The Concourse build now produces a single CI docker image for the entire pipeline; this image contains all the JDKs we need so far: JDK8, JDK11, JDK15. It is easy to add/remove JDKs from our setup. All JDKs locations are configured as environment variables, which makes them available to Gradle.

The pipeline now has:

  • a main build, which does everything with JDK8
  • a JDK11 build, which compiles main sources with JDK8 and compiles+run tests using JDK11
  • a JDK15 build, which compiles main sources with JDK8 and compiles+run tests using JDK15

We can of course discuss options here. Let me know what you think!

@bclozel bclozel self-assigned this Mar 15, 2021
@bclozel bclozel modified the milestones: 5.x Backlog, 5.3.5 Mar 15, 2021
bclozel added a commit that referenced this issue Mar 16, 2021
bclozel added a commit that referenced this issue May 3, 2021
This commit fixes various issues with the configuration of the Gradle
Java toolchain in the build.

First, the configuration of build properties is fixed in the CI pipeline
because it wasn't properly checked.
The JMH plugin is also upgraded and we now configure its toolchain
support.
This commit also rewrites the XJC tasks in the spring-oxm module,
leveraging a Gradle plugin that creates actual compile tasks we can
configure.

See gh-25787
sbrannen added a commit that referenced this issue May 4, 2021
Commit 3eec27a introduced a custom resource filter for projects
imported into Eclipse IDE. However, commit 85eb589 introduced
generated source files within the Gradle 'build' folder, and the filter
prevents Eclipse from seeing the generated sources, resulting in build
errors within the spring-oxm project in Eclipse.

This commit therefore effectively reverts 3eec27a by removing the
resource filter.

See gh-25787
bclozel added a commit that referenced this issue May 4, 2021
Prior to this commit, the task parameters for the CI project checks were
overridden by a task anchor. This commit splits the anchor declaration
and ensures that the `TEST_TOOLCHAIN` setting is set for the JDK
variant builds.

See gh-25787
sbrannen added a commit that referenced this issue May 4, 2021
sbrannen added a commit to sbrannen/spring-framework that referenced this issue May 4, 2021
sbrannen added a commit that referenced this issue May 5, 2021
Prior to this commit, we registered custom values in the build scan for
the main and test toolchains based on input values provided via the
mainToolchain and testToolchain project properties.

Beginning with this commit, the custom values we register are based on
the available metadata for the resolved JDK/JVM for each toolchain.

For example, instead of registering the following custom value...

Test toolchain : JDK11

... we now register the following which includes the vendor, version,
and installation path of the JDK/JVM.

Test toolchain : AdoptOpenJDK 11 (/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home)

Once Gradle's JavaInstallationMetadata includes the exact version, we
will likely use that instead of the installation path.

See gh-25787
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, the Spring Framework build would rely on
setting a custom Java HOME for building all sources and tests
with that JDK.

This approach is not flexible enough, since we would be testing
the source compatibility against a recent JDK, but not a common
case experienced by the community: compiling and running
application code with a recent JDK and the official, JDK8-based
Framework artifacts.
This method is also limiting our choice of JDKs to the ones
currently supported by Gradle itself.

This commit introduces the support of Gradle JVM Toolchains in
the Spring Framework build.

We can now select a specific JDK for compiling the main
SourceSets (Java, Groovy and Kotlin) and another one for
compiling and running the test SourceSets:

`./gradlew check -PmainToolChain=8 -PtestToolchain=15`

Gradle will automatically find the JDKs present on the host or
download one automcatically. You can find out about the ones
installed on your host using:

`./gradlew -q javaToolchains`

Finally, this commit also refactors the CI infrastructure to:

* only have a single CI image (with all the supported JDKs)
* use this new feature to compile with JDK8 but test it
against JDK11 and JDK15.

Closes spring-projectsgh-25787
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
This commit fixes various issues with the configuration of the Gradle
Java toolchain in the build.

First, the configuration of build properties is fixed in the CI pipeline
because it wasn't properly checked.
The JMH plugin is also upgraded and we now configure its toolchain
support.
This commit also rewrites the XJC tasks in the spring-oxm module,
leveraging a Gradle plugin that creates actual compile tasks we can
configure.

See spring-projectsgh-25787
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Commit 3eec27a introduced a custom resource filter for projects
imported into Eclipse IDE. However, commit 85eb589 introduced
generated source files within the Gradle 'build' folder, and the filter
prevents Eclipse from seeing the generated sources, resulting in build
errors within the spring-oxm project in Eclipse.

This commit therefore effectively reverts 3eec27a by removing the
resource filter.

See spring-projectsgh-25787
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, the task parameters for the CI project checks were
overridden by a task anchor. This commit splits the anchor declaration
and ensures that the `TEST_TOOLCHAIN` setting is set for the JDK
variant builds.

See spring-projectsgh-25787
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
Prior to this commit, we registered custom values in the build scan for
the main and test toolchains based on input values provided via the
mainToolchain and testToolchain project properties.

Beginning with this commit, the custom values we register are based on
the available metadata for the resolved JDK/JVM for each toolchain.

For example, instead of registering the following custom value...

Test toolchain : JDK11

... we now register the following which includes the vendor, version,
and installation path of the JDK/JVM.

Test toolchain : AdoptOpenJDK 11 (/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home)

Once Gradle's JavaInstallationMetadata includes the exact version, we
will likely use that instead of the installation path.

See spring-projectsgh-25787
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

3 participants