Skip to content

Commit dac4196

Browse files
authored
build: replace delegates and fix multiple build warnings (#5465)
1 parent 644bd02 commit dac4196

8 files changed

Lines changed: 55 additions & 69 deletions

File tree

alchemist-composeui/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kotlin {
2626
}
2727

2828
sourceSets {
29-
val commonMain by getting {
29+
commonMain {
3030
dependencies {
3131
implementation(libs.bundles.compose)
3232
}

alchemist-factories-generator/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
kotlin {
88
sourceSets {
9-
val jvmMain by getting {
9+
jvmMain {
1010
dependencies {
1111
api(alchemist("api"))
1212
implementation(libs.ksp.api)

alchemist-full/build.gradle.kts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

103108
sealed interface PackagingMethod
104109

@@ -171,19 +176,22 @@ private fun String.extractVersionComponents(): SemVerExtracted {
171176

172177
private val packageDestinationDir = rootProject.layout.buildDirectory.dir("package").directoryProperty
173178
private val baseVersion: Provider<String> = provider { rootProject.version.toString() }
179+
174180
private 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+
180187
private val rpmFileName: Provider<String> =
181188
baseVersion.map { "${rootProject.name}-${RPM.formatVersion(it)}-1.x86_64.rpm" }
189+
182190
private 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+
235244
tasks.assemble.configure { dependsOn(generatePKGBUILD) }
236245

237246
val packageTasks = validFormats.filterIsInstance<ValidPackaging>().map { packaging: ValidPackaging ->
@@ -279,7 +288,7 @@ val packageTasks = validFormats.filterIsInstance<ValidPackaging>().map { packagi
279288

280289
tasks.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+
312322
private val Provider<RegularFile>.fileProperty get(): RegularFileProperty = objects.fileProperty().also {
313323
it.set(this)
314324
it.disallowChanges()

alchemist-graphql/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ plugins {
2222

2323
kotlin {
2424
sourceSets {
25-
val commonMain by getting {
25+
commonMain {
2626
dependencies {
2727
implementation(libs.apollo.runtime)
2828
implementation(libs.kotlin.coroutines.core)
2929
implementation(libs.kotlin.stdlib)
3030
implementation(libs.kotlinx.serialization.json)
3131
}
3232
}
33-
val commonTest by getting {
33+
commonTest {
3434
dependencies {
3535
implementation(kotlin("test"))
3636
}
3737
}
38-
val jvmMain by getting {
38+
jvmMain {
3939
dependencies {
4040
api(alchemist("api"))
4141
api(alchemist("graphql-surrogates"))
@@ -47,7 +47,7 @@ kotlin {
4747
implementation(libs.bundles.ktor.server)
4848
}
4949
}
50-
val jvmTest by getting {
50+
jvmTest {
5151
dependencies {
5252
implementation(libs.kotest.assertions.core)
5353
implementation(libs.kotest.runner)
@@ -58,7 +58,7 @@ kotlin {
5858
implementation(alchemist("test"))
5959
}
6060
}
61-
val jsMain by getting {
61+
jsMain {
6262
dependencies {
6363
implementation(libs.kotlinx.atomicfu.runtime)
6464
}

alchemist-web-renderer/build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ kotlin {
2727
}
2828
}
2929
sourceSets {
30-
val commonMain by getting {
30+
commonMain {
3131
dependencies {
3232
implementation(libs.kotlin.stdlib)
3333
implementation(libs.kotlinx.serialization.json)
@@ -36,13 +36,13 @@ kotlin {
3636
implementation(libs.redux.kotlin.threadsafe)
3737
}
3838
}
39-
val commonTest by getting {
39+
commonTest {
4040
dependencies {
4141
implementation(libs.kotlin.test)
4242
implementation(libs.kotlin.coroutines.test)
4343
}
4444
}
45-
val jvmMain by getting {
45+
jvmMain {
4646
dependencies {
4747
api(alchemist("api"))
4848
implementation(incarnation("sapere"))
@@ -52,15 +52,15 @@ kotlin {
5252
implementation(libs.resourceloader)
5353
}
5454
}
55-
val jvmTest by getting {
55+
jvmTest {
5656
dependencies {
5757
implementation(libs.ktor.server.test.host)
5858
implementation(alchemist("euclidean-geometry"))
5959
implementation(alchemist("implementationbase"))
6060
implementation(alchemist("test"))
6161
}
6262
}
63-
val jsMain by getting {
63+
jsMain {
6464
dependencies {
6565
implementation(libs.bundles.ktor.client)
6666
implementation(libs.bundles.kotlin.react)

build.gradle.kts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import kotlinx.coroutines.runBlocking
2222
import org.danilopianini.gradle.mavencentral.portal.PublishPortalDeployment
2323
import org.gradle.api.internal.ConventionTask
2424
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
25-
import org.jetbrains.dokka.gradle.AbstractDokkaTask
2625
import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask
2726

2827
plugins {
@@ -34,8 +33,6 @@ plugins {
3433
alias(libs.plugins.hugo)
3534
}
3635

37-
val minJavaVersion: String by properties
38-
3936
allprojects {
4037

4138
with(rootProject.libs.plugins) {
@@ -46,7 +43,7 @@ allprojects {
4643
}
4744

4845
multiJvm {
49-
jvmVersionForCompilation.set(minJavaVersion.toInt())
46+
jvmVersionForCompilation.set(providers.gradleProperty("minJavaVersion").map(String::toInt))
5047
maximumSupportedJvmVersion.set(latestJava)
5148
if (isInCI && (isWindows || isMac)) {
5249
/*
@@ -96,21 +93,10 @@ allprojects {
9693
enabled = false
9794
}
9895

99-
/*
100-
* Work around:
101-
* Task ':...:dokkaJavadoc' uses this output of task ':...:jar' without declaring an explicit or implicit dependency.
102-
* This can lead to incorrect results being produced, depending on what order the tasks are executed.
103-
*/
104-
tasks.withType<AbstractDokkaTask>().configureEach {
105-
allprojects.forEach { otherProject ->
106-
dependsOn(otherProject.tasks.withType<org.gradle.jvm.tasks.Jar>().matching { it.name == "jar" })
107-
}
108-
}
109-
11096
if (isInCI) {
11197
signing {
112-
val signingKey: String? by project
113-
val signingPassword: String? by project
98+
val signingKey = project.findProperty("signingKey")?.toString()
99+
val signingPassword = project.findProperty("signingPassword")?.toString()
114100
useInMemoryPgpKeys(signingKey, signingPassword)
115101
}
116102
}
@@ -148,7 +134,7 @@ allprojects {
148134
*/
149135
evaluationDependsOnChildren()
150136

151-
val dokkaGlobalClasspath by configurations.creating
137+
val dokkaGlobalClasspath = configurations.create("dokkaGlobalClasspath")
152138
dependencies {
153139
// Depend on subprojects whose presence is necessary to run
154140
listOf("api", "engine", "loading").forEach { api(alchemist(it)) } // Execution requirements
@@ -167,7 +153,7 @@ dependencies {
167153
dokkaGlobalClasspath(alchemist("full"))
168154
}
169155

170-
val checkMavenCentralPortalPluginClasspath by tasks.registering {
156+
val checkMavenCentralPortalPluginClasspath = tasks.register("checkMavenCentralPortalPluginClasspath") {
171157
group = LifecycleBasePlugin.VERIFICATION_GROUP
172158
description = "Checks that the Maven Central Portal publishing plugin can upload to a local fake endpoint."
173159
val outputFile = layout.buildDirectory.file("reports/checkMavenCentralPortalPluginClasspath/result.txt")
@@ -260,15 +246,16 @@ fun Project.dokkaCopyTask(destination: String): Copy.() -> Unit = {
260246
into(File(websiteDir, "reference/$destination"))
261247
}
262248

263-
val copyGlobalDokkaInTheWebsite by tasks.registering(Copy::class, dokkaCopyTask("kdoc"))
264-
val copyModuleDokkaInTheWebsite by tasks.registering(Copy::class, alchemist("full").dokkaCopyTask("kdoc-modules"))
249+
val copyGlobalDokkaInTheWebsite = tasks.register<Copy>("copyGlobalDokkaInTheWebsite", dokkaCopyTask("kdoc"))
250+
val copyModuleDokkaInTheWebsite =
251+
tasks.register<Copy>("copyModuleDokkaInTheWebsite", alchemist("full").dokkaCopyTask("kdoc-modules"))
265252

266253
tasks.hugoBuild.configure {
267254
outputDirectory = websiteDir
268255
finalizedBy(copyGlobalDokkaInTheWebsite, copyModuleDokkaInTheWebsite)
269256
}
270257

271-
val performWebsiteStringReplacements by tasks.registering {
258+
val performWebsiteStringReplacements = tasks.register("performWebsiteStringReplacements") {
272259
dependsOn(copyGlobalDokkaInTheWebsite, copyModuleDokkaInTheWebsite)
273260
doLast {
274261
val index = File(websiteDir, "index.html")

buildSrc/src/main/kotlin/dokka-convention.gradle.kts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,10 @@ import java.util.concurrent.Executor
1717
import java.util.concurrent.Executors
1818
import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask
1919

20-
/*
21-
* Copyright (C) 2010-2024, Danilo Pianini and contributors
22-
* listed, for each module, in the respective subproject's build.gradle.kts file.
23-
*
24-
* This file is part of Alchemist, and is distributed under the terms of the
25-
* GNU General Public License, with a linking exception,
26-
* as described in the file LICENSE in the Alchemist distribution's top directory.
27-
*/
2820
plugins {
2921
id("org.jetbrains.dokka")
3022
}
3123

32-
val minJavaVersion: String by properties
33-
3424
val fetchEngine: Executor = Executors.newCachedThreadPool()
3525

3626
dokka {
@@ -40,7 +30,7 @@ dokka {
4030
dokkaSourceSets.configureEach {
4131
enableKotlinStdLibDocumentationLink.set(true)
4232
enableJdkDocumentationLink.set(true)
43-
jdkVersion.set(minJavaVersion.toInt())
33+
jdkVersion.set(providers.gradleProperty("minJavaVersion").map(String::toInt))
4434
skipDeprecated.set(false)
4535
skipEmptyPackages.set(true)
4636
/*
@@ -54,10 +44,10 @@ dokka {
5444
.forEach { (path, file) ->
5545
sourceLink {
5646
localDirectory.set(file)
57-
val project = if (project == rootProject) "" else project.name
47+
val projectPath = if (project == rootProject) "" else project.name
5848
val url = "https://github.com/AlchemistSimulator/Alchemist/${
5949
currentCommitHash?.let { "tree/$it" } ?: "blob/master"
60-
}/$project/$path"
50+
}/$projectPath/$path"
6151
remoteUrl.set(uri(url))
6252
remoteLineSuffix.set("#L")
6353
}
@@ -94,6 +84,5 @@ dokka {
9484
}
9585

9686
tasks.withType<DokkaBaseTask>().configureEach {
97-
timeout.set(Duration.ofMinutes(5))
87+
timeout.set(Duration.ofMinutes(15))
9888
}
99-

buildSrc/src/main/kotlin/kotlin-multiplatform-convention.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ kotlin {
3636
val alchemistApi = alchemist("api")
3737
val alchemistMaintenanceTooling = alchemist("maintenance-tooling")
3838
val isNotRootRootProject = project != alchemistMaintenanceTooling && project != alchemistApi
39-
val commonMain by getting {
39+
commonMain {
4040
dependencies {
4141
if (isNotRootRootProject) {
4242
implementation(alchemist("maintenance-tooling"))
4343
}
4444
}
4545
}
46-
val commonTest by getting {
46+
commonTest {
4747
dependencies {
4848
val kotlinTest by catalog
4949
val kotestAssertionsCore by catalog
@@ -53,14 +53,14 @@ kotlin {
5353
implementation(kotestFrameworkEngine)
5454
}
5555
}
56-
val jvmMain by getting {
56+
jvmMain {
5757
dependencies {
5858
if (isNotRootRootProject) {
5959
implementation(alchemistApi)
6060
}
6161
}
6262
}
63-
val jvmTest by getting {
63+
jvmTest {
6464
dependencies {
6565
val `kotest-runner` by catalog
6666
implementation(`kotest-runner`)

0 commit comments

Comments
 (0)