diff --git a/build.gradle b/build.gradle index f0ceefcc0e..7298484afe 100644 --- a/build.gradle +++ b/build.gradle @@ -128,6 +128,10 @@ subprojects { saxonVersion = '11.2' apiGuardianVersion = '1.1.2' + jdkVersion = (project.properties['jdkVersion'] ?: '8') as int + // see https://github.com/gradle/gradle/blob/master/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java + jdkVendor = (project.properties['jdkVendor'] ?: '') as String + JAVA9_SRC = 'src/main/java9' JAVA9_OUT = "${buildDir}/classes/java9/main/" TEST9_SRC = 'src/test/java9' @@ -155,13 +159,10 @@ subprojects { options.incremental = true onlyIf { - (name != "compileJava9" && name != "compileTest9") || JavaVersion.current() != JavaVersion.VERSION_1_8 + (name != "compileJava9" && name != "compileTest9") // || jdkVersion > 8 } } - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - repositories { mavenCentral() maven { @@ -181,6 +182,10 @@ subprojects { } java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor)) + } withJavadocJar() withSourcesJar() } @@ -188,11 +193,13 @@ subprojects { javadoc { failOnError = true maxMemory = "1024M" + javadocTool = javaToolchains.javadocToolFor { + languageVersion = JavaLanguageVersion.of(11) + } + doFirst { options { - if (JavaVersion.current().isJava9Compatible()) { - addBooleanOption('html5', true) - } + addBooleanOption('html5', true) addBooleanOption('Xdoclint:all,-missing', true) links 'https://poi.apache.org/apidocs/dev/' links 'https://docs.oracle.com/javase/8/docs/api/' @@ -253,6 +260,11 @@ subprojects { junitXml.required = true } + javaLauncher = javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor)) + } + // Exclude some tests that are not actually tests or do not run cleanly on purpose exclude '**/BaseTestBorderStyle.class' exclude '**/BaseTestCellUtil.class' @@ -324,14 +336,12 @@ subprojects { systemProperties['java.locale.providers'] = 'JRE,CLDR' doFirst { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { // some options were removed in JDK 18 - if (JavaVersion.current().ordinal() < JavaVersion.VERSION_18.ordinal()) { + if (jdkVersion < 18) { jvmArgs += [ '--illegal-access=warn', ] - } else { - System.out.println("Configuring for JDK 18 or higher") } jvmArgs += [ @@ -403,7 +413,7 @@ subprojects { ignoreFailures = false suppressAnnotations = [ 'org.apache.poi.util.SuppressForbidden' ] // forbiddenapis bundled signatures max supported version is 14 - targetCompatibility = (JavaVersion.VERSION_14.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_14) + // targetCompatibility = (JavaVersion.VERSION_14.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_14) } forbiddenApisMain { diff --git a/jenkins/create_jobs.groovy b/jenkins/create_jobs.groovy index 858d50ce1e..170503b141 100644 --- a/jenkins/create_jobs.groovy +++ b/jenkins/create_jobs.groovy @@ -141,18 +141,18 @@ def defaultMaven = 'maven_3_latest' def defaultSlaves = '(ubuntu)&&!beam&&!cloud-slave&&!H29' def jdkMapping = [ - '1.8': 'jdk_1.8_latest', - '1.10': 'jdk_10_latest', - '1.11': 'jdk_11_latest', - '1.12': 'jdk_12_latest', - '1.13': 'jdk_13_latest', - '1.14': 'jdk_14_latest', - '1.15': 'jdk_15_latest', - '1.16': 'jdk_16_latest', - '1.17': 'jdk_17_latest', - '1.18': 'jdk_18_latest', - 'OpenJDK 1.8': 'adoptopenjdk_hotspot_8u282', - 'IBMJDK': 'ibmjdk_1.8.0_261', + '1.8': [ jenkinsJdk: 'jdk_1.8_latest', jdkVersion: 8, jdkVendor: 'oracle' ], + '1.10': [ jenkinsJdk: 'jdk_10_latest', jdkVersion: 10, jdkVendor: 'oracle' ], + '1.11': [ jenkinsJdk: 'jdk_11_latest', jdkVersion: 11, jdkVendor: 'oracle' ], + '1.12': [ jenkinsJdk: 'jdk_12_latest', jdkVersion: 12, jdkVendor: '' ], + '1.13': [ jenkinsJdk: 'jdk_13_latest', jdkVersion: 13, jdkVendor: '' ], + '1.14': [ jenkinsJdk: 'jdk_14_latest', jdkVersion: 14, jdkVendor: '' ], + '1.15': [ jenkinsJdk: 'jdk_15_latest', jdkVersion: 15, jdkVendor: '' ], + '1.16': [ jenkinsJdk: 'jdk_16_latest', jdkVersion: 16, jdkVendor: '' ], + '1.17': [ jenkinsJdk: 'jdk_17_latest', jdkVersion: 17, jdkVendor: '' ], + '1.18': [ jenkinsJdk: 'jdk_18_latest', jdkVersion: 18, jdkVendor: '' ], + 'OpenJDK 1.8': [ jenkinsJdk: 'adoptopenjdk_hotspot_8u282', jdkVersion: 8, jdkVendor: 'adoptopenjdk' ], + 'IBMJDK': [ jenkinsJdk: 'ibmjdk_1.8.0_261', jdkVersion: 8, jdkVendor: 'ibm' ] ] static def shellEx(def context, String cmd, def poijob) { @@ -302,7 +302,7 @@ poijobs.each { poijob -> } } } - jdk(jdkMapping.get(jdkKey)) + jdk(jdkMapping.get(jdkKey).jenkinsJdk) scm { if (poijob.githubpr) { git { @@ -383,6 +383,10 @@ poijobs.each { poijob -> switches('-Dsonar.organization=apache') switches('-Dsonar.projectKey=poi-parent') switches('-Dsonar.host.url=https://sonarcloud.io') + switches('-PjdkVersion=${jdkMapping.get(jdkKey).jdkVersion}') + if (jdkMapping.get(jdkKey).jdkVendor != '') { + switches('-PjdkVendor=${jdkMapping.get(jdkKey).jdkVendor}') + } tasks('clean') tasks('check') tasks('jacocoTestReport') @@ -434,6 +438,10 @@ poijobs.each { poijob -> if (poijob.saxonTest) { switches('-Psaxon.test=true') } + switches('-PjdkVersion=${jdkMapping.get(jdkKey).jdkVersion}') + if (jdkMapping.get(jdkKey).jdkVendor != '') { + switches('-PjdkVendor=${jdkMapping.get(jdkKey).jdkVendor}') + } } } else { ant { @@ -544,7 +552,7 @@ xmlbeansjobs.each { xjob -> } } } - jdk(jdkMapping.get(jdkKey)) + jdk(jdkMapping.get(jdkKey).jenkinsJdk) scm { svn(xmlbeansSvnBase) { svnNode -> svnNode / browser(class: 'hudson.scm.browsers.ViewSVN') / @@ -573,6 +581,10 @@ xmlbeansjobs.each { xjob -> switches('-Dsonar.organization=apache') switches('-Dsonar.projectKey=apache_xmlbeans') switches('-Dsonar.host.url=https://sonarcloud.io') + switches('-PjdkVersion=${jdkMapping.get(jdkKey).jdkVersion}') + if (jdkMapping.get(jdkKey).jdkVendor != '') { + switches('-PjdkVendor=${jdkMapping.get(jdkKey).jdkVendor}') + } } tasks('clean') tasks('jenkins') diff --git a/poi-examples/build.gradle b/poi-examples/build.gradle index 4fac798e91..1e72a8f778 100644 --- a/poi-examples/build.gradle +++ b/poi-examples/build.gradle @@ -19,7 +19,7 @@ import java.util.regex.Pattern sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } } @@ -58,8 +58,11 @@ final List MODULE_COMPILE_PATH = sourceSets.main.compileClasspath.findAll{ it.pa task compileJava9(type: JavaCompile) { dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } + destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -67,6 +70,11 @@ task compileJava9(type: JavaCompile) { '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}", '--module-path', files(MODULE_COMPILE_PATH).asPath ] + + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -81,7 +89,7 @@ jar { destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } diff --git a/poi-excelant/build.gradle b/poi-excelant/build.gradle index 684eef4ee2..ecd8ed5f07 100644 --- a/poi-excelant/build.gradle +++ b/poi-excelant/build.gradle @@ -23,12 +23,12 @@ configurations { sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } } test { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(TEST9_OUT, builtBy: 'cacheTest9') } } @@ -69,8 +69,10 @@ final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlfor task compileJava9(type: JavaCompile) { dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -78,6 +80,10 @@ task compileJava9(type: JavaCompile) { '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}", '--module-path', files(MAIN_MODULE_PATH).asPath ] + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -90,8 +96,10 @@ task cacheJava9(type: Copy) { task compileTest9(type: JavaCompile) { dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(TEST9_OUT + VERSIONS9) source = file(TEST9_SRC) options.compilerArgs = [ @@ -99,6 +107,10 @@ task compileTest9(type: JavaCompile) { '--module-path', files(TEST_MODULE_PATH).asPath ] classpath = files() + + onlyIf { + jdkVersion > 8 + } } @@ -114,7 +126,7 @@ jar { destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } @@ -148,7 +160,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ] ) { // ignore second module-info.class from main duplicatesStrategy = 'exclude' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from TEST9_SRC include '*.class' } @@ -172,7 +184,7 @@ test { jvmArgs += [ "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}", ] - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { jvmArgs += [ '--add-modules', MODULE_NAME, '--module-path', '../build/dist/maven/poi-excelant-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath, diff --git a/poi-integration/build.gradle b/poi-integration/build.gradle index 36345bcc56..14e7a40ba9 100644 --- a/poi-integration/build.gradle +++ b/poi-integration/build.gradle @@ -29,7 +29,7 @@ configurations { sourceSets { test { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(TEST9_OUT, builtBy: 'cacheTest9') } if (IBMVM) { @@ -98,15 +98,19 @@ final String OOXML_LITE_JAR = "../build/dist/maven/poi-ooxml-lite/poi-ooxml-lite final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)" java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + toolchain { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor)) + } } task compileTest9(type: JavaCompile) { dependsOn 'compileTestJava', ':poi-ooxml:testJar', ':poi-scratchpad:testJar', ':poi-examples:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(TEST9_OUT + VERSIONS9) source = file(TEST9_SRC) options.compilerArgs = [ @@ -114,6 +118,10 @@ task compileTest9(type: JavaCompile) { '--module-path', files(MODULE_COMPILE_PATH).asPath ] classpath = files() + + onlyIf { + jdkVersion > 8 + } } @@ -141,7 +149,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ] ) { // ignore second module-info.class from main duplicatesStrategy = 'exclude' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from TEST9_SRC include '*.class' } @@ -170,7 +178,7 @@ test { jvmArgs += [ "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}", ] - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { jvmArgs += [ '--add-modules', MODULE_NAME, '--module-path', '../build/dist/maven/poi-integration-tests' + File.pathSeparator + files(MODULE_RUNTIME_PATH).asPath, diff --git a/poi-ooxml-full/build.gradle b/poi-ooxml-full/build.gradle index 1a8e91e638..513720a722 100644 --- a/poi-ooxml-full/build.gradle +++ b/poi-ooxml-full/build.gradle @@ -26,7 +26,7 @@ sourceSets { // TypeSystemHolder.class is in the resources output.dir(BEANS_RES, builtBy: 'generate_beans') compileClasspath += files(BEANS_RES) - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } java { @@ -52,13 +52,17 @@ final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path compileJava { dependsOn 'generate_beans' + options.fork = true + options.forkOptions.jvmArgs << '-Xmx2G' } task compileJava9(type: JavaCompile) { dependsOn 'compileJava' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -66,6 +70,10 @@ task compileJava9(type: JavaCompile) { '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.asPath}", '--module-path', files(MAIN_MODULE_PATH).asPath ] + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -136,7 +144,7 @@ task sourceJar(type: Jar) { jar { dependsOn 'sourceJar' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } diff --git a/poi-ooxml-lite-agent/build.gradle b/poi-ooxml-lite-agent/build.gradle index 4b17795650..d89680f47a 100644 --- a/poi-ooxml-lite-agent/build.gradle +++ b/poi-ooxml-lite-agent/build.gradle @@ -17,7 +17,7 @@ sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } } @@ -32,15 +32,19 @@ dependencies { final MODULE_NAME = 'org.apache.poi.ooxml_lite' java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + toolchain { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor)) + } } task compileJava9(type: JavaCompile) { dependsOn 'compileJava' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -50,6 +54,10 @@ task compileJava9(type: JavaCompile) { '--module-path', sourceSets.main.compileClasspath.asPath ] } + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -62,7 +70,7 @@ task cacheJava9(type: Copy) { jar { destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } diff --git a/poi-ooxml-lite/build.gradle b/poi-ooxml-lite/build.gradle index 1d2dd79efe..90a4abfb4e 100644 --- a/poi-ooxml-lite/build.gradle +++ b/poi-ooxml-lite/build.gradle @@ -22,7 +22,7 @@ final String BEANS_RES = "${buildDir}/generated-resources" sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } compileClasspath += files(BEANS_RES) @@ -87,17 +87,26 @@ task compileOoxmlLite(type: Copy) { java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + toolchain { + languageVersion.set(JavaLanguageVersion.of(jdkVersion)) + if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor)) + } +} + +compileJava { + dependsOn 'compileOoxmlLite' + options.fork = true + options.forkOptions.jvmArgs << '-Xmx2G' } processResources.dependsOn 'compileOoxmlLite' -compileJava.dependsOn 'compileOoxmlLite' sourcesJar.dependsOn 'compileOoxmlLite' task compileJava9(type: JavaCompile, dependsOn: 'compileJava') { - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -107,6 +116,10 @@ task compileJava9(type: JavaCompile, dependsOn: 'compileJava') { '--module-path', files(MAIN_MODULE_PATH).asPath ] } + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy, dependsOn: 'compileJava9') { @@ -133,7 +146,7 @@ jar { } } - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } diff --git a/poi-ooxml/build.gradle b/poi-ooxml/build.gradle index 35f51f67d0..b9097c0abf 100644 --- a/poi-ooxml/build.gradle +++ b/poi-ooxml/build.gradle @@ -20,14 +20,14 @@ import java.util.regex.Pattern configurations { runtimeClasspath { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } compileClasspath { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } @@ -39,12 +39,12 @@ configurations { sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } } test { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(TEST9_OUT, builtBy: 'cacheTest9') } } @@ -87,19 +87,19 @@ dependencies { renderImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}" renderImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } renderImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } renderImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } @@ -109,19 +109,19 @@ dependencies { rendersignImplementation "org.apache.xmlgraphics:batik-svggen:${batikVersion}" rendersignImplementation("org.apache.xmlgraphics:batik-svgrasterizer:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } rendersignImplementation("org.apache.xmlgraphics:batik-codec:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } rendersignImplementation("org.apache.xmlgraphics:batik-bridge:${batikVersion}") { exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } @@ -153,7 +153,7 @@ dependencies { broken("org.apache.xmlgraphics:batik-script:${batikVersion}"){ exclude group: 'xalan', module: 'xalan' - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { exclude group: 'xml-apis', module: 'xml-apis' } } @@ -179,8 +179,10 @@ compileJava { task compileJava9(type: JavaCompile) { dependsOn 'compileJava', ':poi:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -188,6 +190,10 @@ task compileJava9(type: JavaCompile) { '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}", '--module-path', files(MAIN_MODULE_PATH).asPath ] + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -200,8 +206,10 @@ task cacheJava9(type: Copy) { task compileTest9(type: JavaCompile) { dependsOn 'compileTestJava', ':poi:testJar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(TEST9_OUT + VERSIONS9) source = file(TEST9_SRC) options.compilerArgs = [ @@ -209,6 +217,10 @@ task compileTest9(type: JavaCompile) { '--module-path', files(TEST_MODULE_PATH).asPath ] classpath = files() + + onlyIf { + jdkVersion > 8 + } } @@ -222,7 +234,7 @@ task cacheTest9(type: Copy) { jar { destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } @@ -242,7 +254,7 @@ task testJar(type: Jar, dependsOn: testClasses) { // ignore second module-info.class from main duplicatesStrategy = 'exclude' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from TEST9_SRC include '*.class' } @@ -321,7 +333,7 @@ test { "-XX:ErrorFile=../build/hs_err_pid%p.log", "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}" ] - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { jvmArgs += [ '--add-modules', MODULE_NAME, '--module-path', '../build/dist/maven/poi-ooxml-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath, diff --git a/poi-scratchpad/build.gradle b/poi-scratchpad/build.gradle index 8c2549643b..9f7ae5e5f7 100644 --- a/poi-scratchpad/build.gradle +++ b/poi-scratchpad/build.gradle @@ -24,12 +24,12 @@ configurations { sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } } test { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(TEST9_OUT, builtBy: 'cacheTest9') } } @@ -64,8 +64,10 @@ final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path task compileJava9(type: JavaCompile) { dependsOn 'compileJava', ':poi:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -73,6 +75,10 @@ task compileJava9(type: JavaCompile) { '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}", '--module-path', files(MAIN_MODULE_PATH).asPath ] + + onlyIf { + jdkVersion > 8 + } } task cacheJava9(type: Copy) { @@ -85,8 +91,10 @@ task cacheJava9(type: Copy) { task compileTest9(type: JavaCompile) { dependsOn 'compileTestJava', ':poi:jar' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } destinationDirectory = file(TEST9_OUT + VERSIONS9) source = file(TEST9_SRC) options.compilerArgs = [ @@ -94,6 +102,10 @@ task compileTest9(type: JavaCompile) { '--module-path', files(TEST_MODULE_PATH).asPath ] classpath = files() + + onlyIf { + jdkVersion > 8 + } } @@ -107,7 +119,7 @@ task cacheTest9(type: Copy) { jar { destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}") - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } @@ -127,7 +139,7 @@ task testJar(type: Jar, dependsOn: testClasses) { // ignore second module-info.class from main duplicatesStrategy = 'exclude' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from TEST9_SRC include '*.class' } @@ -176,7 +188,7 @@ test { systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true' doFirst { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { jvmArgs += [ '--add-modules', MODULE_NAME, '--module-path', '../build/dist/maven/poi-scratchpad-tests' + File.pathSeparator + files(TEST_MODULE_PATH).asPath, diff --git a/poi/build.gradle b/poi/build.gradle index b2aa41d8bb..3516de3966 100644 --- a/poi/build.gradle +++ b/poi/build.gradle @@ -24,7 +24,7 @@ configurations { sourceSets { main { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(JAVA9_OUT, builtBy: 'cacheJava9') } java { @@ -33,7 +33,7 @@ sourceSets { } } test { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { output.dir(TEST9_OUT, builtBy: 'cacheTest9') } } @@ -93,8 +93,9 @@ final List MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MO task compileJava9(type: JavaCompile) { dependsOn 'compileJava' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(11) + } destinationDirectory = file(JAVA9_OUT + VERSIONS9) source = file(JAVA9_SRC) classpath = files() @@ -114,8 +115,11 @@ task cacheJava9(type: Copy) { task compileTest9(type: JavaCompile) { dependsOn 'compileTestJava' - sourceCompatibility = 9 - targetCompatibility = 9 + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(jdkVersion) + if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor) + } + destinationDirectory = file(TEST9_OUT + VERSIONS9) source = file(TEST9_SRC) options.compilerArgs = [ @@ -123,6 +127,10 @@ task compileTest9(type: JavaCompile) { '--module-path', files(MODULE_PATH).asPath ] classpath = files() + + onlyIf { + jdkVersion > 8 + } } @@ -136,7 +144,7 @@ task cacheTest9(type: Copy) { jar { dependsOn cacheJava9 - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from JAVA9_SRC include '*.class' } @@ -156,7 +164,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, cacheTest9 ]) { // ignore second module-info.class from main duplicatesStrategy = 'exclude' - if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + if (jdkVersion == 8) { into('META-INF/versions/9') { from TEST9_SRC include '*.class' } @@ -204,7 +212,7 @@ test { systemProperties['junit.jupiter.execution.parallel.enabled'] = 'true' doFirst { - if (JavaVersion.current() != JavaVersion.VERSION_1_8) { + if (jdkVersion > 8) { jvmArgs << [ '--add-modules', MODULE_NAME, '--module-path', '../build/dist/maven/poi-tests' + File.pathSeparator + files(MODULE_PATH).asPath,