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
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
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}

View File

@@ -14,7 +14,9 @@
* limitations under the License.
*/
import io.github.gradlenexus.publishplugin.CloseNexusStagingRepository
import net.ltgt.gradle.errorprone.errorprone
import org.gradle.kotlin.dsl.withType
// initialize version
@@ -103,6 +105,17 @@ allprojects {
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.
*/
import org.gradle.kotlin.dsl.support.serviceOf
plugins {
`cpp-library`
}
@@ -37,9 +39,14 @@ tasks {
doFirst {
println( "Used Tool Chain:" )
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" ) )
// exclude Java 8 source file if an equally named Java 9+ source file exists
val projectDir = projectDir // necessary for configuration cache
exclude {
if( it.isDirectory )
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
}
}

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 {
@@ -125,10 +104,22 @@ tasks.withType<Sign>().configureEach {
onlyIf { rootProject.hasProperty( "release" ) }
}
// check whether parallel build is enabled
tasks.withType<AbstractPublishToMaven>().configureEach {
doFirst {
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'." )
tasks {
// check whether parallel build is enabled
withType<AbstractPublishToMaven>().configureEach {
doFirst {
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"
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 {
ant.withGroovyBuilder {
"taskdef"(
"name" to "sigtest",
"classname" to "org.netbeans.apitest.Sigtest",
"classpath" to sigtest.asPath )
"classpath" to classpath )
"sigtest"(
"action" to "generate",
"fileName" to "${project.name}-sigtest.txt",
"classpath" to jar.get().outputs.files.asPath,
"fileName" to signatureFile,
"classpath" to jarPath,
"packages" to "com.formdev.flatlaf,com.formdev.flatlaf.themes,com.formdev.flatlaf.util",
"version" to version,
"release" to "1.8", // Java version
"failonerror" to "true" )
"fixcrlf"(
"file" to "${project.name}-sigtest.txt",
"file" to signatureFile,
"eol" to "lf" )
}
}
@@ -125,17 +131,23 @@ tasks {
group = "verification"
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 {
ant.withGroovyBuilder {
"taskdef"(
"name" to "sigtest",
"classname" to "org.netbeans.apitest.Sigtest",
"classpath" to sigtest.asPath )
"classpath" to classpath )
"sigtest"(
"action" to "check",
"fileName" to "${project.name}-sigtest.txt",
"classpath" to jar.get().outputs.files.asPath,
"fileName" to signatureFile,
"classpath" to jarPath,
"packages" to "com.formdev.flatlaf,com.formdev.flatlaf.util",
"version" to 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() )
javaHome += "/.."
interface InjectedOps {
@get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks {
register( "build-natives" ) {
group = "build"
@@ -115,16 +120,18 @@ tasks {
}
} )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast {
// copy shared library to flatlaf-core resources
copy {
injectedOps.fs.copy {
from( linkedFile )
into( nativesDir )
rename( linkedFile.get().asFile.name, libraryName )
}
// dump( linkedFile.asFile.get(), true )
}
// dump( linkedFile, true, injectedOps )
}
if( org.gradle.internal.os.OperatingSystem.current().isLinux &&
@@ -198,43 +205,44 @@ tasks {
"-lgtk-3",
)
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast {
// copy shared library to flatlaf-core resources
copy {
injectedOps.fs.copy {
from( "$outDir/$libraryName" )
into( nativesDir )
}
// dump( file( "$outDir/$libraryName" ), false )
}
// dump( file( "$outDir/$libraryName" ), false, injectedOps )
}
}
}
/*dump
interface InjectedExecOps { @get:Inject val execOps: ExecOperations }
val injected = project.objects.newInstance<InjectedExecOps>()
fun dump( dylib: File, disassemble: Boolean ) {
val dylibDir = dylib.parent
injected.execOps.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
injected.execOps.exec {
commandLine( "objdump",
// commands
"--archive-headers",
"--section-headers",
"--private-headers",
"--reloc",
"--dynamic-reloc",
"--syms",
// files
dylib )
standardOutput = FileOutputStream( "$dylibDir/objdump.txt" )
fun Task.dump( f: Any, disassemble: Boolean, injectedOps: InjectedOps ) {
doLast {
val dylib = if( f is RegularFileProperty) f.get().asFile else f as File
val dylibDir = dylib.parent
injectedOps.e.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
injectedOps.e.exec {
commandLine( "objdump",
// commands
"--archive-headers",
"--section-headers",
"--private-headers",
"--reloc",
"--dynamic-reloc",
"--syms",
// files
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*/

View File

@@ -43,8 +43,10 @@ var javaHome = System.getProperty( "java.home" )
if( javaHome.endsWith( "jre" ) )
javaHome += "/.."
interface InjectedExecOps { @get:Inject val execOps: ExecOperations }
val injected = project.objects.newInstance<InjectedExecOps>()
interface InjectedOps {
@get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks {
register( "build-natives" ) {
@@ -96,12 +98,14 @@ tasks {
}
} )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast {
// 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 {
injectedOps.fs.copy {
from( linkedFile )
into( nativesDir )
rename( linkedFile.get().asFile.name, libraryName )
@@ -110,9 +114,9 @@ tasks {
/*dump
val dylib = linkedFile.asFile.get()
val dylibDir = dylib.parent
injected.execOps.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
injected.execOps.exec { commandLine( "size", "-m", dylib ); standardOutput = FileOutputStream( "$dylibDir/size-m.txt" ) }
injected.execOps.exec {
injectedOps.e.exec { commandLine( "size", dylib ); standardOutput = FileOutputStream( "$dylibDir/size.txt" ) }
injectedOps.e.exec { commandLine( "size", "-m", dylib ); standardOutput = FileOutputStream( "$dylibDir/size-m.txt" ) }
injectedOps.e.exec {
commandLine( "objdump",
// commands
"--archive-headers",
@@ -130,8 +134,8 @@ tasks {
dylib )
standardOutput = FileOutputStream( "$dylibDir/objdump.txt" )
}
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" ) }
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" ) }
dump*/
}
}

View File

@@ -41,8 +41,10 @@ var javaHome = System.getProperty( "java.home" )
if( javaHome.endsWith( "jre" ) )
javaHome += "/.."
interface InjectedExecOps { @get:Inject val execOps: ExecOperations }
val injected = project.objects.newInstance<InjectedExecOps>()
interface InjectedOps {
@get:Inject val fs: FileSystemOperations
@get:Inject val e: ExecOperations
}
tasks {
register( "build-natives" ) {
@@ -89,9 +91,11 @@ tasks {
}
} )
val injectedOps = project.objects.newInstance<InjectedOps>()
doLast {
// copy shared library to flatlaf-core resources
copy {
injectedOps.fs.copy {
from( linkedFile )
into( nativesDir )
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 dll = linkedFile.asFile.get()
val dllDir = dll.parent
injected.execOps.exec { commandLine( dumpbin, "/all", "/rawdata:none", "/out:$dllDir/objdump.txt", dll ) }
injected.execOps.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, "/all", "/rawdata:none", "/out:$dllDir/objdump.txt", dll ) }
injectedOps.e.exec { commandLine( dumpbin, "/all", "/out:$dllDir/full-contents.txt", dll ) }
injectedOps.e.exec { commandLine( dumpbin, "/disasm", "/out:$dllDir/disassemble.txt", dll ) }
dump*/
}
}

View File

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

View File

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