Gradle: use configuration cache

This commit is contained in:
Karl Tauber
2025-11-25 11:51:41 +01:00
parent 19c86cf1f7
commit c8e2e78955
11 changed files with 135 additions and 86 deletions

View File

@@ -107,7 +107,7 @@ jobs:
- name: Cache Gradle - name: Cache Gradle
uses: ./.github/actions/cache-gradle uses: ./.github/actions/cache-gradle
- name: Release a new stable version to Maven Central - name: Release a new stable version to Maven Central and build demo and theme editor
run: ./gradlew publishToSonatype closeSonatypeStagingRepository :flatlaf-demo:build :flatlaf-theme-editor:build -PskipFonts -Prelease -Dorg.gradle.parallel=false run: ./gradlew publishToSonatype closeSonatypeStagingRepository :flatlaf-demo:build :flatlaf-theme-editor:build -PskipFonts -Prelease -Dorg.gradle.parallel=false
env: env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

View File

@@ -14,7 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
import io.github.gradlenexus.publishplugin.CloseNexusStagingRepository
import net.ltgt.gradle.errorprone.errorprone import net.ltgt.gradle.errorprone.errorprone
import org.gradle.kotlin.dsl.withType
// initialize version // initialize version
@@ -103,6 +105,17 @@ allprojects {
languageVersion.set( JavaLanguageVersion.of( 25 ) ) languageVersion.set( JavaLanguageVersion.of( 25 ) )
} ) } )
} }
// mark some publishing related tasks as not compatible with configuration cache
withType<Sign>().configureEach {
notCompatibleWithConfigurationCache( "not compatible" )
}
withType<PublishToMavenRepository>().configureEach {
notCompatibleWithConfigurationCache( "not compatible" )
}
withType<CloseNexusStagingRepository>().configureEach {
notCompatibleWithConfigurationCache( "not compatible" )
}
} }

View File

@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
import org.gradle.kotlin.dsl.support.serviceOf
plugins { plugins {
`cpp-library` `cpp-library`
} }
@@ -37,9 +39,14 @@ tasks {
doFirst { doFirst {
println( "Used Tool Chain:" ) println( "Used Tool Chain:" )
println( " - ${toolChain.get()}" ) println( " - ${toolChain.get()}" )
println( "Available Tool Chains:" ) }
toolChains.forEach {
println( " - $it" ) if( !project.gradle.serviceOf<BuildFeatures>().configurationCache.active.get() ) {
doFirst {
println( "Available Tool Chains:" )
toolChains.forEach {
println( " - $it" )
}
} }
} }
} }

View File

@@ -45,10 +45,11 @@ if( !exclude ) {
setSrcDirs( listOf( "src/main/module-info", "src/main/java", "src/main/java9" ) ) setSrcDirs( listOf( "src/main/module-info", "src/main/java", "src/main/java9" ) )
// exclude Java 8 source file if an equally named Java 9+ source file exists // exclude Java 8 source file if an equally named Java 9+ source file exists
val projectDir = projectDir // necessary for configuration cache
exclude { exclude {
if( it.isDirectory ) if( it.isDirectory )
return@exclude false return@exclude false
val java9file = file( "${projectDir}/src/main/java9/${it.path}" ) val java9file = File( "${projectDir}/src/main/java9/${it.path}" )
java9file.exists() && java9file != it.file java9file.exists() && java9file != it.file
} }
} }

View File

@@ -85,27 +85,6 @@ publishing {
} }
} }
} }
/*
repositories {
maven {
name = "MavenCentral"
val releasesRepoUrl = "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/"
val snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
url = uri( if( rootProject.hasProperty( "release" ) ) releasesRepoUrl else snapshotsRepoUrl )
credentials {
// get from gradle.properties
val sonatypeUsername: String? by project
val sonatypePassword: String? by project
username = System.getenv( "SONATYPE_USERNAME" ) ?: sonatypeUsername
password = System.getenv( "SONATYPE_PASSWORD" ) ?: sonatypePassword
}
}
}
*/
} }
signing { signing {
@@ -125,10 +104,22 @@ tasks.withType<Sign>().configureEach {
onlyIf { rootProject.hasProperty( "release" ) } onlyIf { rootProject.hasProperty( "release" ) }
} }
// check whether parallel build is enabled tasks {
tasks.withType<AbstractPublishToMaven>().configureEach { // check whether parallel build is enabled
doFirst { withType<AbstractPublishToMaven>().configureEach {
if( System.getProperty( "org.gradle.parallel" ) == "true" ) doFirst {
throw RuntimeException( "Publishing does not work correctly with enabled parallel build. Disable parallel build with VM option '-Dorg.gradle.parallel=false'." ) if( System.getProperty( "org.gradle.parallel" ) == "true" )
throw RuntimeException( "Publishing does not work correctly with enabled parallel build. Disable parallel build with VM option '-Dorg.gradle.parallel=false'." )
}
}
register( "publishToSonatypeAndCloseStagingRepo" ) {
group = "publishing"
description = "Publish to Sonatype Maven Central and close staging repository"
dependsOn(
"publishToSonatype",
":closeSonatypeStagingRepository"
)
} }
} }

View File

@@ -98,24 +98,30 @@ tasks {
group = "verification" group = "verification"
dependsOn( "jar" ) dependsOn( "jar" )
// necessary for configuration cache
val classpath = sigtest.asPath
val signatureFile = "${project.name}-sigtest.txt"
val jarPath = jar.get().outputs.files.asPath
val version = version
doLast { doLast {
ant.withGroovyBuilder { ant.withGroovyBuilder {
"taskdef"( "taskdef"(
"name" to "sigtest", "name" to "sigtest",
"classname" to "org.netbeans.apitest.Sigtest", "classname" to "org.netbeans.apitest.Sigtest",
"classpath" to sigtest.asPath ) "classpath" to classpath )
"sigtest"( "sigtest"(
"action" to "generate", "action" to "generate",
"fileName" to "${project.name}-sigtest.txt", "fileName" to signatureFile,
"classpath" to jar.get().outputs.files.asPath, "classpath" to jarPath,
"packages" to "com.formdev.flatlaf,com.formdev.flatlaf.themes,com.formdev.flatlaf.util", "packages" to "com.formdev.flatlaf,com.formdev.flatlaf.themes,com.formdev.flatlaf.util",
"version" to version, "version" to version,
"release" to "1.8", // Java version "release" to "1.8", // Java version
"failonerror" to "true" ) "failonerror" to "true" )
"fixcrlf"( "fixcrlf"(
"file" to "${project.name}-sigtest.txt", "file" to signatureFile,
"eol" to "lf" ) "eol" to "lf" )
} }
} }
@@ -125,17 +131,23 @@ tasks {
group = "verification" group = "verification"
dependsOn( "jar" ) dependsOn( "jar" )
// necessary for configuration cache
val classpath = sigtest.asPath
val signatureFile = "${project.name}-sigtest.txt"
val jarPath = jar.get().outputs.files.asPath
val version = version
doLast { doLast {
ant.withGroovyBuilder { ant.withGroovyBuilder {
"taskdef"( "taskdef"(
"name" to "sigtest", "name" to "sigtest",
"classname" to "org.netbeans.apitest.Sigtest", "classname" to "org.netbeans.apitest.Sigtest",
"classpath" to sigtest.asPath ) "classpath" to classpath )
"sigtest"( "sigtest"(
"action" to "check", "action" to "check",
"fileName" to "${project.name}-sigtest.txt", "fileName" to signatureFile,
"classpath" to jar.get().outputs.files.asPath, "classpath" to jarPath,
"packages" to "com.formdev.flatlaf,com.formdev.flatlaf.util", "packages" to "com.formdev.flatlaf,com.formdev.flatlaf.util",
"version" to version, "version" to version,
"release" to "1.8", // Java version "release" to "1.8", // Java version

View File

@@ -40,6 +40,11 @@ var javaHome = System.getProperty( "java.home" )
if( javaHome.endsWith( "jre" ) && !file( "${javaHome}/include" ).exists() ) if( javaHome.endsWith( "jre" ) && !file( "${javaHome}/include" ).exists() )
javaHome += "/.." javaHome += "/.."
interface InjectedOps {
@get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks { tasks {
register( "build-natives" ) { register( "build-natives" ) {
group = "build" group = "build"
@@ -115,16 +120,18 @@ tasks {
} }
} ) } )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast { doLast {
// copy shared library to flatlaf-core resources // copy shared library to flatlaf-core resources
copy { injectedOps.fs.copy {
from( linkedFile ) from( linkedFile )
into( nativesDir ) into( nativesDir )
rename( linkedFile.get().asFile.name, libraryName ) rename( linkedFile.get().asFile.name, libraryName )
} }
// dump( linkedFile.asFile.get(), true )
} }
// dump( linkedFile, true, injectedOps )
} }
if( org.gradle.internal.os.OperatingSystem.current().isLinux && if( org.gradle.internal.os.OperatingSystem.current().isLinux &&
@@ -198,43 +205,44 @@ tasks {
"-lgtk-3", "-lgtk-3",
) )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast { doLast {
// copy shared library to flatlaf-core resources // copy shared library to flatlaf-core resources
copy { injectedOps.fs.copy {
from( "$outDir/$libraryName" ) from( "$outDir/$libraryName" )
into( nativesDir ) into( nativesDir )
} }
// dump( file( "$outDir/$libraryName" ), false )
} }
// dump( file( "$outDir/$libraryName" ), false, injectedOps )
} }
} }
} }
/*dump /*dump
interface InjectedExecOps { @get:Inject val execOps: ExecOperations } fun Task.dump( f: Any, disassemble: Boolean, injectedOps: InjectedOps ) {
val injected = project.objects.newInstance<InjectedExecOps>() doLast {
val dylib = if( f is RegularFileProperty) f.get().asFile else f as File
fun dump( dylib: File, disassemble: Boolean ) { val dylibDir = dylib.parent
injectedOps.e.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
val dylibDir = dylib.parent injectedOps.e.exec {
injected.execOps.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) } commandLine( "objdump",
injected.execOps.exec { // commands
commandLine( "objdump", "--archive-headers",
// commands "--section-headers",
"--archive-headers", "--private-headers",
"--section-headers", "--reloc",
"--private-headers", "--dynamic-reloc",
"--reloc", "--syms",
"--dynamic-reloc", // files
"--syms", dylib )
// files standardOutput = FileOutputStream( "$dylibDir/objdump.txt" )
dylib ) }
standardOutput = FileOutputStream( "$dylibDir/objdump.txt" ) if( disassemble )
injectedOps.e.exec { commandLine( "objdump", "--disassemble-all", dylib ); standardOutput = FileOutputStream( "$dylibDir/disassemble.txt" ) }
injectedOps.e.exec { commandLine( "objdump", "--full-contents", dylib ); standardOutput = FileOutputStream( "$dylibDir/full-contents.txt" ) }
injectedOps.e.exec { commandLine( "hexdump", dylib ); standardOutput = FileOutputStream( "$dylibDir/hexdump.txt" ) }
} }
if( disassemble )
injected.execOps.exec { commandLine( "objdump", "--disassemble-all", dylib ); standardOutput = FileOutputStream( "$dylibDir/disassemble.txt" ) }
injected.execOps.exec { commandLine( "objdump", "--full-contents", dylib ); standardOutput = FileOutputStream( "$dylibDir/full-contents.txt" ) }
injected.execOps.exec { commandLine( "hexdump", dylib ); standardOutput = FileOutputStream( "$dylibDir/hexdump.txt" ) }
} }
dump*/ dump*/

View File

@@ -43,8 +43,10 @@ var javaHome = System.getProperty( "java.home" )
if( javaHome.endsWith( "jre" ) ) if( javaHome.endsWith( "jre" ) )
javaHome += "/.." javaHome += "/.."
interface InjectedExecOps { @get:Inject val execOps: ExecOperations } interface InjectedOps {
val injected = project.objects.newInstance<InjectedExecOps>() @get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks { tasks {
register( "build-natives" ) { register( "build-natives" ) {
@@ -96,12 +98,14 @@ tasks {
} }
} ) } )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast { doLast {
// sign shared library // sign shared library
// injected.execOps.exec { commandLine( "codesign", "-s", "FormDev Software GmbH", "--timestamp", "${linkedFile.asFile.get()}" ) } // injectedOps.e.exec { commandLine( "codesign", "-s", "FormDev Software GmbH", "--timestamp", "${linkedFile.asFile.get()}" ) }
// copy shared library to flatlaf-core resources // copy shared library to flatlaf-core resources
copy { injectedOps.fs.copy {
from( linkedFile ) from( linkedFile )
into( nativesDir ) into( nativesDir )
rename( linkedFile.get().asFile.name, libraryName ) rename( linkedFile.get().asFile.name, libraryName )
@@ -110,9 +114,9 @@ tasks {
/*dump /*dump
val dylib = linkedFile.asFile.get() val dylib = linkedFile.asFile.get()
val dylibDir = dylib.parent val dylibDir = dylib.parent
injected.execOps.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) } injectedOps.e.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
injected.execOps.exec { commandLine( "size", "-m", dylib ); standardOutput = FileOutputStream( "$dylibDir/size-m.txt" ) } injectedOps.e.exec { commandLine( "size", "-m", dylib ); standardOutput = FileOutputStream( "$dylibDir/size-m.txt" ) }
injected.execOps.exec { injectedOps.e.exec {
commandLine( "objdump", commandLine( "objdump",
// commands // commands
"--archive-headers", "--archive-headers",
@@ -130,8 +134,8 @@ tasks {
dylib ) dylib )
standardOutput = FileOutputStream( "$dylibDir/objdump.txt" ) standardOutput = FileOutputStream( "$dylibDir/objdump.txt" )
} }
injected.execOps.exec { commandLine( "objdump", "--disassemble-all", dylib ); standardOutput = FileOutputStream( "$dylibDir/disassemble.txt" ) } injectedOps.e.exec { commandLine( "objdump", "--disassemble-all", dylib ); standardOutput = FileOutputStream( "$dylibDir/disassemble.txt" ) }
injected.execOps.exec { commandLine( "objdump", "--full-contents", dylib ); standardOutput = FileOutputStream( "$dylibDir/full-contents.txt" ) } injectedOps.e.exec { commandLine( "objdump", "--full-contents", dylib ); standardOutput = FileOutputStream( "$dylibDir/full-contents.txt" ) }
dump*/ dump*/
} }
} }

View File

@@ -41,8 +41,10 @@ var javaHome = System.getProperty( "java.home" )
if( javaHome.endsWith( "jre" ) ) if( javaHome.endsWith( "jre" ) )
javaHome += "/.." javaHome += "/.."
interface InjectedExecOps { @get:Inject val execOps: ExecOperations } interface InjectedOps {
val injected = project.objects.newInstance<InjectedExecOps>() @get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks { tasks {
register( "build-natives" ) { register( "build-natives" ) {
@@ -89,9 +91,11 @@ tasks {
} }
} ) } )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast { doLast {
// copy shared library to flatlaf-core resources // copy shared library to flatlaf-core resources
copy { injectedOps.fs.copy {
from( linkedFile ) from( linkedFile )
into( nativesDir ) into( nativesDir )
rename( linkedFile.get().asFile.name, libraryName ) rename( linkedFile.get().asFile.name, libraryName )
@@ -101,9 +105,9 @@ tasks {
val dumpbin = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/dumpbin.exe" val dumpbin = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/dumpbin.exe"
val dll = linkedFile.asFile.get() val dll = linkedFile.asFile.get()
val dllDir = dll.parent val dllDir = dll.parent
injected.execOps.exec { commandLine( dumpbin, "/all", "/rawdata:none", "/out:$dllDir/objdump.txt", dll ) } injectedOps.e.exec { commandLine( dumpbin, "/all", "/rawdata:none", "/out:$dllDir/objdump.txt", dll ) }
injected.execOps.exec { commandLine( dumpbin, "/all", "/out:$dllDir/full-contents.txt", dll ) } injectedOps.e.exec { commandLine( dumpbin, "/all", "/out:$dllDir/full-contents.txt", dll ) }
injected.execOps.exec { commandLine( dumpbin, "/disasm", "/out:$dllDir/disassemble.txt", dll ) } injectedOps.e.exec { commandLine( dumpbin, "/disasm", "/out:$dllDir/disassemble.txt", dll ) }
dump*/ dump*/
} }
} }

View File

@@ -32,16 +32,25 @@ flatlafModuleInfo {
dependsOn( ":flatlaf-fonts-inter:jar" ) dependsOn( ":flatlaf-fonts-inter:jar" )
} }
interface InjectedOps {
@get:Inject val fs: FileSystemOperations
}
tasks { tasks {
register( "build-for-debugging" ) { register( "build-for-debugging" ) {
group = "build" group = "build"
dependsOn( "build" ) dependsOn( "build" )
// necessary for configuration cache
val jar = project.tasks["jar"].outputs.files
val runtimeJars = configurations.runtimeClasspath.get().files
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast { doLast {
copy { injectedOps.fs.copy {
from( project.tasks["jar"].outputs ) from( jar )
from( configurations.runtimeClasspath ) from( runtimeJars )
into( "run" ) into( "run" )
rename( "-[0-9][0-9.]*[0-9]", "-999" ) rename( "-[0-9][0-9.]*[0-9]", "-999" )
} }

View File

@@ -17,5 +17,5 @@
flatlaf.releaseVersion = 3.6.2 flatlaf.releaseVersion = 3.6.2
flatlaf.developmentVersion = 3.7-SNAPSHOT flatlaf.developmentVersion = 3.7-SNAPSHOT
org.gradle.parallel = true org.gradle.configuration-cache = true
# org.gradle.warning.mode = all # org.gradle.warning.mode = all