diff --git a/build.gradle b/build.gradle index 24be2186d0..e597ed582e 100644 --- a/build.gradle +++ b/build.gradle @@ -60,7 +60,8 @@ configure(allprojects) { project -> entry 'aspectjtools' entry 'aspectjweaver' } - dependencySet(group: 'org.codehaus.groovy', version: '2.5.9') { + // If customJavaHome has been set, we assume we need Groovy 3.0 for testing purposes. + dependencySet(group: 'org.codehaus.groovy', version: System.getProperty("customJavaHome") ? '3.0.0-rc-3' : '2.5.9') { entry 'groovy' entry 'groovy-jsr223' entry 'groovy-templates' @@ -305,6 +306,7 @@ configure([rootProject] + javaProjects) { project -> apply plugin: "java-test-fixtures" apply plugin: "checkstyle" apply plugin: 'org.springframework.build.compile' + apply from: "${rootDir}/gradle/custom-java-home.gradle" apply from: "${rootDir}/gradle/ide.gradle" pluginManager.withPlugin("kotlin") { diff --git a/gradle/build-scan-user-data.gradle b/gradle/build-scan-user-data.gradle index d4f483d66f..c9463e7f33 100644 --- a/gradle/build-scan-user-data.gradle +++ b/gradle/build-scan-user-data.gradle @@ -4,6 +4,8 @@ tagCiOrLocal() addCiMetadata() addGitMetadata() addTestTaskMetadata() +addCustomJavaHomeMetadata() +addCustomJavaSourceVersionMetadata() void tagOs() { buildScan.tag System.getProperty('os.name') @@ -60,6 +62,20 @@ void addTestTaskMetadata() { } } +void addCustomJavaHomeMetadata() { + def customJavaHome = System.getProperty("customJavaHome") + if (customJavaHome) { + buildScan.value "Custom JAVA_HOME", customJavaHome + } +} + +void addCustomJavaSourceVersionMetadata() { + def customJavaSourceVersion = System.getProperty("customJavaSourceVersion") + if (customJavaSourceVersion) { + buildScan.value "Custom Java Source Version", customJavaSourceVersion + } +} + boolean isCi() { isBamboo() } diff --git a/gradle/custom-java-home.gradle b/gradle/custom-java-home.gradle new file mode 100644 index 0000000000..39d2619e9a --- /dev/null +++ b/gradle/custom-java-home.gradle @@ -0,0 +1,87 @@ +// ----------------------------------------------------------------------------- +// +// This script adds support for the following two JVM system properties +// that control the build for alternative JDKs (i.e., a JDK other than +// the one used to launch the Gradle process). +// +// - customJavaHome: absolute path to the alternate JDK installation to +// use to compile Java code and execute tests. Setting this system +// property causes Groovy 3.0 RC3 to be used instead of 2.5.x. This +// system property is also used in spring-oxm.gradle to determine +// whether JiBX is supported. +// +// - customJavaSourceVersion: Java version supplied to the `--release` +// command line flag to control the Java source and target +// compatibility version. Supported versions include 9 or higher. +// Do not set this system property if Java 8 should be used. +// +// Examples: +// +// ./gradlew -DcustomJavaHome=/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home test +// +// ./gradlew --no-build-cache -DcustomJavaHome=/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home test +// +// ./gradlew -DcustomJavaHome=/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home -DcustomJavaSourceVersion=14 test +// +// ----------------------------------------------------------------------------- + +import org.gradle.internal.os.OperatingSystem +// import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompile + +def customJavaHome = System.getProperty("customJavaHome") + +if (customJavaHome) { + def javacExecutable = customJavaHome + "/bin/javac" + def javaExecutable = customJavaHome + "/bin/java" + if (OperatingSystem.current().isWindows()) { + javacExecutable += ".exe" + javaExecutable += ".exe" + } + + def customJavaSourceVersion = System.getProperty("customJavaSourceVersion") + + tasks.withType(JavaCompile) { + logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable) + doFirst { + // Avoid compiler warnings for non-existing path entries + classpath = classpath.filter { it.exists() } + } + options.fork = true + options.forkOptions.executable = javacExecutable + options.compilerArgs -= "-Werror" + if (customJavaSourceVersion) { + options.compilerArgs += [ "--release", customJavaSourceVersion] + inputs.property("customJavaSourceVersion", customJavaSourceVersion) + } + inputs.property("customJavaHome", customJavaHome) + } + + tasks.withType(GroovyCompile) { + logger.info("Java compiler for " + it.name + " task in " + project.name + ": " + javacExecutable) + options.fork = true + options.forkOptions.executable = javacExecutable + if (customJavaSourceVersion) { + options.compilerArgs += [ "--release", customJavaSourceVersion] + inputs.property("customJavaSourceVersion", customJavaSourceVersion) + } + inputs.property("customJavaHome", customJavaHome) + } + + /* + tasks.withType(KotlinJvmCompile) { + logger.info("Java home for " + it.name + " task in " + project.name + ": " + customJavaHome) + kotlinOptions.jdkHome = customJavaHome + inputs.property("customJavaHome", customJavaHome) + } + */ + + tasks.withType(Test) { + logger.info("Java executable for " + it.name + " task in " + project.name + ": " + javaExecutable) + executable = javaExecutable + inputs.property("customJavaHome", customJavaHome) + if (customJavaSourceVersion) { + inputs.property("customJavaSourceVersion", customJavaSourceVersion) + } + } + +} diff --git a/spring-oxm/spring-oxm.gradle b/spring-oxm/spring-oxm.gradle index 530245c126..9d23276d22 100644 --- a/spring-oxm/spring-oxm.gradle +++ b/spring-oxm/spring-oxm.gradle @@ -74,8 +74,9 @@ dependencies { testRuntime("com.sun.xml.bind:jaxb-impl") } -// JiBX compiler is currently not compatible with JDK 9+ -if (JavaVersion.current() == JavaVersion.VERSION_1_8) { +// JiBX compiler is currently not compatible with JDK 9+. +// If customJavaHome has been set, we assume the custom JDK version is 9+. +if ((JavaVersion.current() == JavaVersion.VERSION_1_8) && !System.getProperty("customJavaSourceVersion")) { compileTestJava { def bindingXml = "${projectDir}/src/test/resources/org/springframework/oxm/jibx/binding.xml"