Gradle:
Some checks failed
CI / build (push) Has been cancelled
CI / release (push) Has been cancelled
Error Prone / error-prone (push) Has been cancelled

- 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

@@ -40,9 +40,9 @@ jobs:
# - Java LTS versions (11, 17, ...)
# - latest Java version(s)
- name: Build with Java 8
- name: Build with Java 11 LTS
if: github.repository == 'JFormDesigner/FlatLaf'
run: ./gradlew build clean -Dtoolchain=8
run: ./gradlew build clean -Dtoolchain=11
- name: Build with Java 17 LTS
if: github.repository == 'JFormDesigner/FlatLaf'
@@ -57,9 +57,9 @@ jobs:
run: ./gradlew build clean -Dtoolchain=25
# build with Java 11 for snapshot
# build with Java 8 for snapshot
- name: Build with Java 11 LTS
- name: Build with Java 8
run: ./gradlew build
- name: Upload artifacts to GitHub Actions

View File

@@ -34,4 +34,4 @@ jobs:
cache: gradle
- name: Check with Error Prone
run: ./gradlew errorprone clean
run: ./gradlew errorprone

View File

@@ -16,6 +16,8 @@
import net.ltgt.gradle.errorprone.errorprone
// initialize version
group = "com.formdev"
version = property( if( hasProperty( "release" ) ) "flatlaf.releaseVersion" else "flatlaf.developmentVersion" ) as String
@@ -24,18 +26,16 @@ val pullRequestNumber = findProperty( "github.event.pull_request.number" )
if( pullRequestNumber != null )
version = "PR-${pullRequestNumber}-SNAPSHOT"
allprojects {
// apply version to all subprojects
subprojects {
version = rootProject.version
repositories {
mavenCentral()
}
}
// check required Java version
if( JavaVersion.current() < JavaVersion.VERSION_1_8 )
throw RuntimeException( "Java 8 or later required (running ${System.getProperty( "java.version" )})" )
// initialize toolchain version (default is Java 8)
val toolchainJavaVersion: String by extra {
System.getProperty( "toolchain", "8" )
}
// log version, Gradle and Java versions
println()
@@ -43,7 +43,7 @@ println( "----------------------------------------------------------------------
println( "FlatLaf Version: ${version}" )
println( "Gradle ${gradle.gradleVersion} at ${gradle.gradleHomeDir}" )
println( "Java ${System.getProperty( "java.version" )}" )
println( "Java toolchain ${System.getProperty( "toolchain", "11" )}" )
println( "Java toolchain ${toolchainJavaVersion}" )
println()
@@ -53,6 +53,10 @@ plugins {
}
allprojects {
repositories {
mavenCentral()
}
tasks {
withType<JavaCompile>().configureEach {
sourceCompatibility = "1.8"
@@ -139,6 +143,15 @@ allprojects {
)
}
}
// Error Prone requires at lease Java 11
val java = (project as ExtensionAware).extensions.getByName("java") as JavaPluginExtension
val javaToolchains = (project as ExtensionAware).extensions.getByName("javaToolchains") as JavaToolchainService
if( java.toolchain.languageVersion.get().asInt() < 11 ) {
javaCompiler.set( javaToolchains.compilerFor {
languageVersion.set( JavaLanguageVersion.of( 11 ) )
} )
}
}
}
}

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 )
}

View File

@@ -43,15 +43,13 @@ tasks {
dependsOn( ":flatlaf-intellij-themes:jar" )
// dependsOn( ":flatlaf-natives-jna:jar" )
manifest {
attributes( "Main-Class" to "com.formdev.flatlaf.demo.FlatLafDemo" )
if( java.toolchain.languageVersion.get().asInt() >= 9 )
attributes( "Multi-Release" to "true" )
manifest.attributes(
"Main-Class" to "com.formdev.flatlaf.demo.FlatLafDemo",
"Multi-Release" to "true",
// allow loading FlatLaf native library in Java 24+ (see https://openjdk.org/jeps/472)
attributes( "Enable-Native-Access" to "ALL-UNNAMED" )
}
"Enable-Native-Access" to "ALL-UNNAMED",
)
exclude( "module-info.class" )
exclude( "META-INF/versions/*/module-info.class" )

View File

@@ -41,15 +41,13 @@ tasks {
dependsOn( ":flatlaf-fonts-roboto:jar" )
dependsOn( ":flatlaf-fonts-roboto-mono:jar" )
manifest {
attributes( "Main-Class" to "com.formdev.flatlaf.themeeditor.FlatLafThemeEditor" )
if( java.toolchain.languageVersion.get().asInt() >= 9 )
attributes( "Multi-Release" to "true" )
manifest.attributes(
"Main-Class" to "com.formdev.flatlaf.themeeditor.FlatLafThemeEditor",
"Multi-Release" to "true",
// allow loading FlatLaf native library in Java 24+ (see https://openjdk.org/jeps/472)
attributes( "Enable-Native-Access" to "ALL-UNNAMED" )
}
"Enable-Native-Access" to "ALL-UNNAMED",
)
exclude( "module-info.class" )
exclude( "META-INF/versions/*/module-info.class" )