From df8212b49e886d942e25d41906c6c3b4af15776a Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Thu, 30 Oct 2025 18:56:11 +0100 Subject: [PATCH] Gradle: - 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 --- .github/workflows/ci.yml | 8 ++--- .github/workflows/error-prone.yml | 2 +- build.gradle.kts | 33 +++++++++++++------ .../src/main/kotlin/flatlaf-java9.gradle.kts | 16 ++++++++- .../kotlin/flatlaf-module-info.gradle.kts | 16 ++++++++- .../main/kotlin/flatlaf-toolchain.gradle.kts | 4 ++- flatlaf-demo/build.gradle.kts | 12 +++---- flatlaf-theme-editor/build.gradle.kts | 12 +++---- 8 files changed, 71 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95549cac..797cf4e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/error-prone.yml b/.github/workflows/error-prone.yml index cd2523f0..e248a849 100644 --- a/.github/workflows/error-prone.yml +++ b/.github/workflows/error-prone.yml @@ -34,4 +34,4 @@ jobs: cache: gradle - name: Check with Error Prone - run: ./gradlew errorprone clean + run: ./gradlew errorprone diff --git a/build.gradle.kts b/build.gradle.kts index b4d2cdfc..6b745cf7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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().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 ) ) + } ) + } } } } diff --git a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts index 7dbf175d..a653b4d4 100644 --- a/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-java9.gradle.kts @@ -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( "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 { diff --git a/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts index af46b748..2c3ec39a 100644 --- a/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-module-info.gradle.kts @@ -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 { diff --git a/buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts b/buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts index 21cfcfed..90fe4df9 100644 --- a/buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts +++ b/buildSrc/src/main/kotlin/flatlaf-toolchain.gradle.kts @@ -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 ) } diff --git a/flatlaf-demo/build.gradle.kts b/flatlaf-demo/build.gradle.kts index c685db32..d94a501f 100644 --- a/flatlaf-demo/build.gradle.kts +++ b/flatlaf-demo/build.gradle.kts @@ -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" ) diff --git a/flatlaf-theme-editor/build.gradle.kts b/flatlaf-theme-editor/build.gradle.kts index 359fdadb..4be34812 100644 --- a/flatlaf-theme-editor/build.gradle.kts +++ b/flatlaf-theme-editor/build.gradle.kts @@ -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" )