Skip to content

Commit

Permalink
Configure the Gradle toolchain to use Java 23
Browse files Browse the repository at this point in the history
In order to be able to fix spring-projectsgh-34140 which requires using at least a
Java 22 compiler, this commit intends to change the configuration of the
Gradle toolchain to use Java 23, while setting the Java release to
Java 17 (or other versions when using MRJARs) when relevant in order to
keep the current Java 17 baseline.

See spring-projectsgh-34220
  • Loading branch information
sdeleuze committed Jan 9, 2025
1 parent 63770ba commit 4c1c27d
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void apply(Project project) {
private void applyJavaCompileConventions(Project project) {
project.getExtensions().getByType(JavaPluginExtension.class).toolchain(toolchain -> {
toolchain.getVendor().set(JvmVendorSpec.BELLSOFT);
toolchain.getLanguageVersion().set(JavaLanguageVersion.of(17));
toolchain.getLanguageVersion().set(JavaLanguageVersion.of(23));
});
SpringFrameworkExtension frameworkExtension = project.getExtensions().getByType(SpringFrameworkExtension.class);
project.afterEvaluate(p -> {
Expand All @@ -83,6 +83,7 @@ private void applyJavaCompileConventions(Project project) {
compileTask.getOptions().setCompilerArgs(COMPILER_ARGS);
compileTask.getOptions().getCompilerArgumentProviders().add(frameworkExtension.asArgumentProvider());
compileTask.getOptions().setEncoding("UTF-8");
setJavaRelease(compileTask);
});
p.getTasks().withType(JavaCompile.class)
.matching(compileTask -> compileTask.getName().startsWith(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME)
Expand All @@ -91,9 +92,23 @@ private void applyJavaCompileConventions(Project project) {
compileTask.getOptions().setCompilerArgs(TEST_COMPILER_ARGS);
compileTask.getOptions().getCompilerArgumentProviders().add(frameworkExtension.asArgumentProvider());
compileTask.getOptions().setEncoding("UTF-8");
setJavaRelease(compileTask);
});

});
}

private void setJavaRelease(JavaCompile task) {
int defaultVersion = 17;
int releaseVersion = defaultVersion;
int compilerVersion = task.getJavaCompiler().get().getMetadata().getLanguageVersion().asInt();
for (int version = defaultVersion ; version <= compilerVersion ; version++) {
if (task.getName().contains("Java" + version)) {
releaseVersion = version;
break;
}
}
task.getOptions().getRelease().set(releaseVersion);
}

}

0 comments on commit 4c1c27d

Please sign in to comment.