- default is now Java 8 toolchain (to fix Eclipse project import)
- `src/main/module-info` and `src/main/java9` are compiled with Java 11 toolchain (if global toolchain is Java 8)
- `src/main/module-info` and `src/main/java9` are no longer imported into Eclipse projects
- task `errorprone` now uses at least Java 11 toolchain
This commit is contained in:
Karl Tauber
2025-10-30 18:56:11 +01:00
parent c583a21bf7
commit df8212b49e
8 changed files with 71 additions and 32 deletions

View File

@@ -18,7 +18,14 @@ plugins {
java
}
if( java.toolchain.languageVersion.get().asInt() >= 9 ) {
// for Eclipse IDE project import, exclude if:
// - plugin "eclipse" is applied; e.g. if running in Eclipse IDE with buildship plugin
// - no taskNames specified at command line; e.g. if buildship synchronizes projects
val exclude =
rootProject.plugins.hasPlugin( "eclipse" ) &&
gradle.startParameter.taskNames.isEmpty()
if( !exclude ) {
sourceSets {
create( "java9" ) {
java {
@@ -35,6 +42,13 @@ if( java.toolchain.languageVersion.get().asInt() >= 9 ) {
named<JavaCompile>( "compileJava9Java" ) {
sourceCompatibility = "9"
targetCompatibility = "9"
// if global toolchain is Java 8, then use Java 11 to build
if( java.toolchain.languageVersion.get().asInt() < 9 ) {
javaCompiler.set( javaToolchains.compilerFor {
languageVersion.set( JavaLanguageVersion.of( 11 ) )
} )
}
}
jar {

View File

@@ -29,7 +29,14 @@ plugins {
java
}
if( java.toolchain.languageVersion.get().asInt() >= 9 ) {
// for Eclipse IDE project import, exclude if:
// - plugin "eclipse" is applied; e.g. if running in Eclipse IDE with buildship plugin
// - no taskNames specified at command line; e.g. if buildship synchronizes projects
val exclude =
rootProject.plugins.hasPlugin( "eclipse" ) &&
gradle.startParameter.taskNames.isEmpty()
if( !exclude ) {
sourceSets {
create( "module-info" ) {
java {
@@ -58,6 +65,13 @@ if( java.toolchain.languageVersion.get().asInt() >= 9 ) {
options.compilerArgs.add( "--module-path" )
options.compilerArgs.add( configurations.runtimeClasspath.get().asPath
+ File.pathSeparator + configurations.compileClasspath.get().asPath )
// if global toolchain is Java 8, then use Java 11 to build
if( java.toolchain.languageVersion.get().asInt() < 9 ) {
javaCompiler.set( javaToolchains.compilerFor {
languageVersion.set( JavaLanguageVersion.of( 11 ) )
} )
}
}
jar {

View File

@@ -18,6 +18,8 @@ plugins {
java
}
val toolchainJavaVersion: String by rootProject.extra
java.toolchain {
languageVersion = JavaLanguageVersion.of( System.getProperty( "toolchain", "11" ) )
languageVersion = JavaLanguageVersion.of( toolchainJavaVersion )
}