@@ -56,7 +56,7 @@ application {
5656}
5757
5858// Shadow Jar
59- tasks.withType<ShadowJar > {
59+ tasks.withType<ShadowJar >().configureEach {
6060 manifest {
6161 attributes(
6262 mapOf (
@@ -82,23 +82,28 @@ tasks.withType<ShadowJar> {
8282 mergeServiceFiles()
8383 duplicatesStrategy = DuplicatesStrategy .INCLUDE
8484 destinationDirectory.set(rootProject.layout.buildDirectory.map { it.dir(" shadow" ) })
85- // Run the jar and check the output
86- val minJavaVersion: String by properties
87- val javaExecutable = javaToolchains.launcherFor { languageVersion.set(JavaLanguageVersion .of(minJavaVersion)) }
88- .map { it.executablePath.asFile.absolutePath }
89- val testShadowJar = testShadowJar(javaExecutable, archiveFile)
90- testShadowJar.configure {
91- dependsOn(this @withType)
92- }
93- this .finalizedBy(testShadowJar)
94- tasks.assemble.configure { dependsOn(testShadowJar) }
9585}
9686
87+ val javaExecutable = javaToolchains.launcherFor {
88+ languageVersion.set(
89+ providers.gradleProperty(" minJavaVersion" ).map(JavaLanguageVersion ::of),
90+ )
91+ }
92+
93+ val testShadowJar = testShadowJar(
94+ javaExecutable.map { it.executablePath.asFile.absolutePath },
95+ tasks.shadowJar.flatMap { it.archiveFile },
96+ )
97+ testShadowJar.configure { dependsOn(tasks.shadowJar) }
98+ tasks.shadowJar.configure { finalizedBy(testShadowJar) }
99+ tasks.assemble.configure { dependsOn(testShadowJar) }
100+
97101// Disable distTar and distZip
98- val toDisable = with (tasks) {
99- listOf (distTar, distZip, jpackage, shadowDistZip, shadowDistTar).map { it.name }
102+ with (tasks) {
103+ listOf (distTar, distZip, jpackage, shadowDistZip, shadowDistTar).forEach {
104+ it.configure { enabled = false }
105+ }
100106}
101- tasks.matching { it.name in toDisable }.configureEach { enabled = false }
102107
103108sealed interface PackagingMethod
104109
@@ -171,19 +176,22 @@ private fun String.extractVersionComponents(): SemVerExtracted {
171176
172177private val packageDestinationDir = rootProject.layout.buildDirectory.dir(" package" ).directoryProperty
173178private val baseVersion: Provider <String > = provider { rootProject.version.toString() }
179+
174180private fun ImageType.formatVersion (version : String ): String = when (this ) {
175181 MSI , EXE -> version.substringBefore(' -' )
176182 DMG , PKG -> version.extractVersionComponents().asMangledVersion()
177183 RPM -> version.replace(' -' , ' .' )
178184 else -> version
179185}
186+
180187private val rpmFileName: Provider <String > =
181188 baseVersion.map { " ${rootProject.name} -${RPM .formatVersion(it)} -1.x86_64.rpm" }
189+
182190private val rpmFileProvider: RegularFileProperty = rpmFileName.flatMap { fileName ->
183191 packageDestinationDir.file(fileName)
184192}.fileProperty
185193
186- val generatePKGBUILD by tasks.registering {
194+ val generatePKGBUILD = tasks.register( " generatePKGBUILD " ) {
187195 group = " Distribution"
188196 description = " Generates a valid PKGBUILD by replacing values in the template file"
189197 if (validFormats.none { it is ValidPackaging && it.format == RPM }) {
@@ -232,6 +240,7 @@ val generatePKGBUILD by tasks.registering {
232240 outputDir.resolve(" PKGBUILD" ).writeText(pkgbuildContent)
233241 }
234242}
243+
235244tasks.assemble.configure { dependsOn(generatePKGBUILD) }
236245
237246val packageTasks = validFormats.filterIsInstance<ValidPackaging >().map { packaging: ValidPackaging ->
@@ -279,7 +288,7 @@ val packageTasks = validFormats.filterIsInstance<ValidPackaging>().map { packagi
279288
280289tasks.assemble.configure { dependsOn(packageTasks) }
281290
282- tasks.withType<AbstractArchiveTask > {
291+ tasks.withType<AbstractArchiveTask >().configureEach {
283292 duplicatesStrategy = DuplicatesStrategy .INCLUDE
284293}
285294
@@ -309,6 +318,7 @@ private val Provider<Directory>.directoryProperty get(): DirectoryProperty = obj
309318 it.set(this )
310319 it.disallowChanges()
311320}
321+
312322private val Provider <RegularFile >.fileProperty get(): RegularFileProperty = objects.fileProperty().also {
313323 it.set(this )
314324 it.disallowChanges()
0 commit comments