Fix Gradle Java Toolchain configuration
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
This commit is contained in:
parent
b18cf3c873
commit
85eb589c2e
|
@ -9,8 +9,9 @@ plugins {
|
||||||
id "io.freefair.aspectj" version '5.1.1' apply false
|
id "io.freefair.aspectj" version '5.1.1' apply false
|
||||||
id "com.github.ben-manes.versions" version '0.28.0'
|
id "com.github.ben-manes.versions" version '0.28.0'
|
||||||
id "com.github.johnrengelman.shadow" version "6.1.0" apply false
|
id "com.github.johnrengelman.shadow" version "6.1.0" apply false
|
||||||
id "me.champeau.gradle.jmh" version "0.5.2" apply false
|
id "me.champeau.jmh" version "0.6.4" apply false
|
||||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.4.32" apply false
|
id "org.jetbrains.kotlin.plugin.serialization" version "1.4.32" apply false
|
||||||
|
id "org.unbroken-dome.xjc" version '2.0.0' apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
|
|
@ -231,7 +231,6 @@ jobs:
|
||||||
image: ci-image
|
image: ci-image
|
||||||
file: git-repo/ci/tasks/check-project.yml
|
file: git-repo/ci/tasks/check-project.yml
|
||||||
params:
|
params:
|
||||||
MAIN_TOOLCHAIN: 8
|
|
||||||
TEST_TOOLCHAIN: 11
|
TEST_TOOLCHAIN: 11
|
||||||
<<: *build-project-task-params
|
<<: *build-project-task-params
|
||||||
on_failure:
|
on_failure:
|
||||||
|
@ -258,7 +257,6 @@ jobs:
|
||||||
image: ci-image
|
image: ci-image
|
||||||
file: git-repo/ci/tasks/check-project.yml
|
file: git-repo/ci/tasks/check-project.yml
|
||||||
params:
|
params:
|
||||||
MAIN_TOOLCHAIN: 8
|
|
||||||
TEST_TOOLCHAIN: 15
|
TEST_TOOLCHAIN: 15
|
||||||
<<: *build-project-task-params
|
<<: *build-project-task-params
|
||||||
on_failure:
|
on_failure:
|
||||||
|
|
|
@ -4,6 +4,6 @@ set -e
|
||||||
source $(dirname $0)/common.sh
|
source $(dirname $0)/common.sh
|
||||||
|
|
||||||
pushd git-repo > /dev/null
|
pushd git-repo > /dev/null
|
||||||
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false -Dorg.gradle.java.installations.fromEnv=JDK11,JDK15 \
|
./gradlew -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false -Porg.gradle.java.installations.fromEnv=JDK11,JDK15 \
|
||||||
-PmainToolchain=$MAIN_TOOLCHAIN -PtestToolchain=$TEST_TOOLCHAIN --no-daemon --max-workers=4 check
|
-PmainToolchain=${MAIN_TOOLCHAIN} -PtestToolchain=${TEST_TOOLCHAIN} --no-daemon --max-workers=4 check
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
|
@ -4,12 +4,12 @@ apply plugin: 'org.springframework.build.optional-dependencies'
|
||||||
// Uncomment the following for Shadow support in the jmhJar block.
|
// Uncomment the following for Shadow support in the jmhJar block.
|
||||||
// Currently commented out due to ZipException: archive is not a ZIP archive
|
// Currently commented out due to ZipException: archive is not a ZIP archive
|
||||||
// apply plugin: 'com.github.johnrengelman.shadow'
|
// apply plugin: 'com.github.johnrengelman.shadow'
|
||||||
apply plugin: 'me.champeau.gradle.jmh'
|
apply plugin: 'me.champeau.jmh'
|
||||||
apply from: "$rootDir/gradle/publications.gradle"
|
apply from: "$rootDir/gradle/publications.gradle"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
jmh 'org.openjdk.jmh:jmh-core:1.25'
|
jmh 'org.openjdk.jmh:jmh-core:1.28'
|
||||||
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.25'
|
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.28'
|
||||||
jmh 'net.sf.jopt-simple:jopt-simple:4.6'
|
jmh 'net.sf.jopt-simple:jopt-simple:4.6'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
* <li>a JDK11 toolchain for compiling and running the test SourceSet
|
* <li>a JDK11 toolchain for compiling and running the test SourceSet
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
* By default, the build will fall back to using the current JDK and 1.8 language level for all sourceSets.
|
||||||
|
*
|
||||||
* Gradle will automatically detect JDK distributions in well-known locations.
|
* Gradle will automatically detect JDK distributions in well-known locations.
|
||||||
* The following command will list the detected JDKs on the host.
|
* The following command will list the detected JDKs on the host.
|
||||||
* {@code
|
* {@code
|
||||||
|
@ -29,13 +31,34 @@
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
def mainToolchainConfigured() {
|
||||||
|
return project.hasProperty('mainToolchain') && project.mainToolchain
|
||||||
|
}
|
||||||
|
|
||||||
|
def testToolchainConfigured() {
|
||||||
|
return project.hasProperty('testToolchain') && project.testToolchain
|
||||||
|
}
|
||||||
|
|
||||||
|
def mainToolchainLanguageVersion() {
|
||||||
|
if (mainToolchainConfigured()) {
|
||||||
|
return JavaLanguageVersion.of(project.mainToolchain.toString())
|
||||||
|
}
|
||||||
|
return JavaLanguageVersion.of(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
def testToolchainLanguageVersion() {
|
||||||
|
if (testToolchainConfigured()) {
|
||||||
|
return JavaLanguageVersion.of(project.testToolchain.toString())
|
||||||
|
}
|
||||||
|
return mainToolchainLanguageVersion()
|
||||||
|
}
|
||||||
|
|
||||||
plugins.withType(JavaPlugin) {
|
plugins.withType(JavaPlugin) {
|
||||||
// Configure the Java Toolchain if the 'mainToolchain' property is defined
|
// Configure the Java Toolchain if the 'mainToolchain' is configured
|
||||||
if (project.hasProperty('mainToolchain') && project.mainToolchain) {
|
if (mainToolchainConfigured()) {
|
||||||
def mainLanguageVersion = JavaLanguageVersion.of(project.mainToolchain.toString())
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion = mainLanguageVersion
|
languageVersion = mainToolchainLanguageVersion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +69,8 @@ plugins.withType(JavaPlugin) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Configure a specific Java Toolchain for compiling and running tests if the 'testToolchain' property is defined
|
// Configure a specific Java Toolchain for compiling and running tests if the 'testToolchain' property is defined
|
||||||
if (project.hasProperty('testToolchain') && project.testToolchain) {
|
if (testToolchainConfigured()) {
|
||||||
def testLanguageVersion = JavaLanguageVersion.of(project.testToolchain.toString());
|
def testLanguageVersion = testToolchainLanguageVersion()
|
||||||
tasks.withType(JavaCompile).matching { it.name.contains("Test") }.configureEach {
|
tasks.withType(JavaCompile).matching { it.name.contains("Test") }.configureEach {
|
||||||
javaCompiler = javaToolchains.compilerFor {
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
languageVersion = testLanguageVersion
|
languageVersion = testLanguageVersion
|
||||||
|
@ -63,17 +86,17 @@ plugins.withType(JavaPlugin) {
|
||||||
|
|
||||||
plugins.withType(GroovyPlugin) {
|
plugins.withType(GroovyPlugin) {
|
||||||
// Fallback to JDK8
|
// Fallback to JDK8
|
||||||
if (!project.hasProperty('mainToolchain')) {
|
if (!mainToolchainConfigured()) {
|
||||||
compileGroovy {
|
compileGroovy {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the Kotlin compiler if the 'mainToolchain' property is defined
|
|
||||||
pluginManager.withPlugin("kotlin") {
|
pluginManager.withPlugin("kotlin") {
|
||||||
if (project.hasProperty('mainToolchain') && project.mainToolchain) {
|
// Configure the Kotlin compiler if the 'mainToolchain' property is defined
|
||||||
def mainLanguageVersion = JavaLanguageVersion.of(project.mainToolchain.toString());
|
if (mainToolchainConfigured()) {
|
||||||
|
def mainLanguageVersion = mainToolchainLanguageVersion()
|
||||||
def compiler = javaToolchains.compilerFor {
|
def compiler = javaToolchains.compilerFor {
|
||||||
languageVersion = mainLanguageVersion
|
languageVersion = mainLanguageVersion
|
||||||
}
|
}
|
||||||
|
@ -107,8 +130,8 @@ pluginManager.withPlugin("kotlin") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (project.hasProperty('testToolchain') && project.testToolchain) {
|
if (testToolchainConfigured()) {
|
||||||
def testLanguageVersion = JavaLanguageVersion.of(project.testToolchain.toString());
|
def testLanguageVersion = testToolchainLanguageVersion()
|
||||||
def compiler = javaToolchains.compilerFor {
|
def compiler = javaToolchains.compilerFor {
|
||||||
languageVersion = testLanguageVersion
|
languageVersion = testLanguageVersion
|
||||||
}
|
}
|
||||||
|
@ -121,4 +144,20 @@ pluginManager.withPlugin("kotlin") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure the JMH plugin to use the toolchain for generating and running JMH bytecode
|
||||||
|
pluginManager.withPlugin("me.champeau.jmh") {
|
||||||
|
if (mainToolchainConfigured() || testToolchainConfigured()) {
|
||||||
|
tasks.matching { it.name.contains('jmh') && it.hasProperty('javaLauncher') }.configureEach {
|
||||||
|
javaLauncher.set(javaToolchains.launcherFor {
|
||||||
|
languageVersion.set(testToolchainLanguageVersion())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
tasks.withType(JavaCompile).matching { it.name.contains("Jmh") }.configureEach {
|
||||||
|
javaCompiler = javaToolchains.compilerFor {
|
||||||
|
languageVersion = testToolchainLanguageVersion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -166,7 +166,10 @@ public class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static class Handler {
|
static class Handler {
|
||||||
|
|
||||||
|
public Handler() {
|
||||||
|
}
|
||||||
|
|
||||||
public String handle(Integer intArg, String stringArg) {
|
public String handle(Integer intArg, String stringArg) {
|
||||||
return intArg + "-" + stringArg;
|
return intArg + "-" + stringArg;
|
||||||
|
@ -181,7 +184,7 @@ public class InvocableHandlerMethodTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ExceptionRaisingArgumentResolver implements HandlerMethodArgumentResolver {
|
static class ExceptionRaisingArgumentResolver implements HandlerMethodArgumentResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsParameter(MethodParameter parameter) {
|
public boolean supportsParameter(MethodParameter parameter) {
|
||||||
|
|
|
@ -183,6 +183,8 @@ public class InvocableHandlerMethodTests {
|
||||||
|
|
||||||
private AtomicReference<String> result = new AtomicReference<>();
|
private AtomicReference<String> result = new AtomicReference<>();
|
||||||
|
|
||||||
|
public Handler() {
|
||||||
|
}
|
||||||
|
|
||||||
public String getResult() {
|
public String getResult() {
|
||||||
return this.result.get();
|
return this.result.get();
|
||||||
|
|
|
@ -1,56 +1,24 @@
|
||||||
|
plugins {
|
||||||
|
id "org.unbroken-dome.xjc"
|
||||||
|
}
|
||||||
|
|
||||||
description = "Spring Object/XML Marshalling"
|
description = "Spring Object/XML Marshalling"
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
jibx
|
jibx
|
||||||
xjc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
jibx "org.jibx:jibx-bind:1.3.3"
|
jibx "org.jibx:jibx-bind:1.3.3"
|
||||||
jibx "org.apache.bcel:bcel:6.0"
|
jibx "org.apache.bcel:bcel:6.0"
|
||||||
xjc "javax.xml.bind:jaxb-api:2.3.1"
|
|
||||||
xjc "com.sun.xml.bind:jaxb-core:2.3.0.1"
|
|
||||||
xjc "com.sun.xml.bind:jaxb-impl:2.3.0.1"
|
|
||||||
xjc "com.sun.xml.bind:jaxb-xjc:2.3.1"
|
|
||||||
xjc "com.sun.activation:javax.activation:1.2.0"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.genSourcesDir = "${buildDir}/generated-sources"
|
xjc {
|
||||||
ext.flightSchema = "${projectDir}/src/test/resources/org/springframework/oxm/flight.xsd"
|
xjcVersion = '2.2'
|
||||||
|
}
|
||||||
task genJaxb {
|
sourceSets {
|
||||||
ext.sourcesDir = "${genSourcesDir}/jaxb"
|
test {
|
||||||
ext.classesDir = "${buildDir}/classes/jaxb"
|
xjcTargetPackage = 'org.springframework.oxm.jaxb.test'
|
||||||
|
|
||||||
inputs.files(flightSchema).withPathSensitivity(PathSensitivity.RELATIVE)
|
|
||||||
outputs.dir classesDir
|
|
||||||
|
|
||||||
doLast() {
|
|
||||||
project.ant {
|
|
||||||
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
|
|
||||||
classpath: configurations.xjc.asPath
|
|
||||||
mkdir(dir: sourcesDir)
|
|
||||||
mkdir(dir: classesDir)
|
|
||||||
|
|
||||||
xjc(destdir: sourcesDir, schema: flightSchema,
|
|
||||||
package: "org.springframework.oxm.jaxb.test") {
|
|
||||||
produces(dir: sourcesDir, includes: "**/*.java")
|
|
||||||
}
|
|
||||||
|
|
||||||
javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
|
|
||||||
debugLevel: "lines,vars,source",
|
|
||||||
classpath: configurations.xjc.asPath) {
|
|
||||||
src(path: sourcesDir)
|
|
||||||
include(name: "**/*.java")
|
|
||||||
include(name: "*.java")
|
|
||||||
}
|
|
||||||
|
|
||||||
copy(todir: classesDir) {
|
|
||||||
fileset(dir: sourcesDir, erroronmissingdir: false) {
|
|
||||||
exclude(name: "**/*.java")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +35,7 @@ dependencies {
|
||||||
testCompile("org.codehaus.jettison:jettison") {
|
testCompile("org.codehaus.jettison:jettison") {
|
||||||
exclude group: "stax", module: "stax-api"
|
exclude group: "stax", module: "stax-api"
|
||||||
}
|
}
|
||||||
testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
|
//testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||||
testCompile("org.xmlunit:xmlunit-assertj")
|
testCompile("org.xmlunit:xmlunit-assertj")
|
||||||
testCompile("org.xmlunit:xmlunit-matchers")
|
testCompile("org.xmlunit:xmlunit-matchers")
|
||||||
testRuntime("com.sun.xml.bind:jaxb-core")
|
testRuntime("com.sun.xml.bind:jaxb-core")
|
||||||
|
@ -76,7 +44,7 @@ dependencies {
|
||||||
|
|
||||||
// JiBX compiler is currently not compatible with JDK 9+.
|
// JiBX compiler is currently not compatible with JDK 9+.
|
||||||
// If customJavaHome has been set, we assume the custom JDK version is 9+.
|
// If customJavaHome has been set, we assume the custom JDK version is 9+.
|
||||||
if ((JavaVersion.current() == JavaVersion.VERSION_1_8) && !System.getProperty("customJavaSourceVersion")) {
|
if ((JavaVersion.current() == JavaVersion.VERSION_1_8) && !project.hasProperty("testToolchain")) {
|
||||||
compileTestJava {
|
compileTestJava {
|
||||||
def bindingXml = "${projectDir}/src/test/resources/org/springframework/oxm/jibx/binding.xml"
|
def bindingXml = "${projectDir}/src/test/resources/org/springframework/oxm/jibx/binding.xml"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright 2002-2021 the original author or authors.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||||
|
targetNamespace="http://samples.springframework.org/flight"
|
||||||
|
xmlns:tns="http://samples.springframework.org/flight">
|
||||||
|
<element name="flights">
|
||||||
|
<complexType>
|
||||||
|
<sequence>
|
||||||
|
<element name="flight" type="tns:flightType"
|
||||||
|
maxOccurs="unbounded">
|
||||||
|
</element>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
</element>
|
||||||
|
<element name="flight" type="tns:flightType"/>
|
||||||
|
<complexType name="flightType">
|
||||||
|
<sequence>
|
||||||
|
<element name="number" type="long"/>
|
||||||
|
</sequence>
|
||||||
|
</complexType>
|
||||||
|
</schema>
|
|
@ -6,6 +6,8 @@
|
||||||
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="AnnotationLocation|AnnotationUseStyle|AtclauseOrder|AvoidNestedBlocks|FinalClass|HideUtilityClassConstructor|InnerTypeLast|JavadocStyle|JavadocType|JavadocVariable|LeftCurly|MultipleVariableDeclarations|NeedBraces|OneTopLevelClass|OuterTypeFilename|RequireThis|SpringCatch|SpringJavadoc|SpringNoThis" />
|
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="AnnotationLocation|AnnotationUseStyle|AtclauseOrder|AvoidNestedBlocks|FinalClass|HideUtilityClassConstructor|InnerTypeLast|JavadocStyle|JavadocType|JavadocVariable|LeftCurly|MultipleVariableDeclarations|NeedBraces|OneTopLevelClass|OuterTypeFilename|RequireThis|SpringCatch|SpringJavadoc|SpringNoThis" />
|
||||||
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]org[\\/]springframework[\\/].+(Tests|Suite)" checks="IllegalImport" id="bannedJUnitJupiterImports" />
|
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]org[\\/]springframework[\\/].+(Tests|Suite)" checks="IllegalImport" id="bannedJUnitJupiterImports" />
|
||||||
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="SpringJUnit5" message="should not be public" />
|
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="SpringJUnit5" message="should not be public" />
|
||||||
|
<!-- generated sources -->
|
||||||
|
<suppress files="[\\/]build[\\/]generated[\\/]sources[\\/]" checks=".*" />
|
||||||
|
|
||||||
<!-- JMH benchmarks -->
|
<!-- JMH benchmarks -->
|
||||||
<suppress files="[\\/]src[\\/]jmh[\\/]java[\\/]org[\\/]springframework[\\/]" checks="JavadocVariable|JavadocStyle|InnerTypeLast" />
|
<suppress files="[\\/]src[\\/]jmh[\\/]java[\\/]org[\\/]springframework[\\/]" checks="JavadocVariable|JavadocStyle|InnerTypeLast" />
|
||||||
|
|
Loading…
Reference in New Issue