Browse Source

Configure Gradle toolchain auto-provisioning

This commit configures the Foojay resolver plugin in the Gradle build in
order to auto-provision a required JDK distribution if it's not present
already on the host.

Currently the Spring Framework build requires both a JDK 17 and a JDK 21
distribution to build artifacts.

Closes gh-30474
pull/31471/head
Brian Clozel 1 year ago
parent
commit
8708a21143
  1. 8
      buildSrc/src/main/java/org/springframework/build/JavaConventions.java
  2. 1
      settings.gradle

8
buildSrc/src/main/java/org/springframework/build/JavaConventions.java

@ -27,6 +27,8 @@ import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.jvm.toolchain.JavaLanguageVersion; import org.gradle.jvm.toolchain.JavaLanguageVersion;
import org.gradle.jvm.toolchain.JavaToolchainSpec;
import org.gradle.jvm.toolchain.JvmVendorSpec;
/** /**
* {@link Plugin} that applies conventions for compiling Java sources in Spring Framework. * {@link Plugin} that applies conventions for compiling Java sources in Spring Framework.
@ -70,8 +72,10 @@ public class JavaConventions {
* @param project the current project * @param project the current project
*/ */
private void applyJavaCompileConventions(Project project) { private void applyJavaCompileConventions(Project project) {
project.getExtensions().getByType(JavaPluginExtension.class) project.getExtensions().getByType(JavaPluginExtension.class).toolchain(toolchain -> {
.getToolchain().getLanguageVersion().set(JavaLanguageVersion.of(17)); toolchain.getVendor().set(JvmVendorSpec.BELLSOFT);
toolchain.getLanguageVersion().set(JavaLanguageVersion.of(17));
});
project.getTasks().withType(JavaCompile.class) project.getTasks().withType(JavaCompile.class)
.matching(compileTask -> compileTask.getName().equals(JavaPlugin.COMPILE_JAVA_TASK_NAME)) .matching(compileTask -> compileTask.getName().equals(JavaPlugin.COMPILE_JAVA_TASK_NAME))
.forEach(compileTask -> { .forEach(compileTask -> {

1
settings.gradle

@ -1,6 +1,7 @@
plugins { plugins {
id "com.gradle.enterprise" version "3.14" id "com.gradle.enterprise" version "3.14"
id "io.spring.ge.conventions" version "0.0.13" id "io.spring.ge.conventions" version "0.0.13"
id "org.gradle.toolchains.foojay-resolver-convention" version "0.7.0"
} }
include "spring-aop" include "spring-aop"

Loading…
Cancel
Save