Skip to content

Commit 21c982c

Browse files
CopilotjGleitz
andcommitted
Fix Gradle 9 compatibility: upgrade nexus plugin, fix deprecated APIs
- Upgrade io.github.gradle-nexus.publish-plugin from 1.3.0 to 2.0.0 (fixes ClassNotFoundException for DefaultDecoratedConvention removed in Gradle 9) - Rename closeAndReleaseStagingRepository to closeAndReleaseStagingRepositories (breaking change in nexus plugin 2.0.0) - Replace deprecated KotlinCompilerVersion with version-less kotlin() dependency - Migrate kotlinOptions DSL to compilerOptions DSL (deprecated in Kotlin 2.3.10) - Replace -Xopt-in with -opt-in compiler flag - Replace deprecated String.toLowerCase() with lowercase() - Replace deprecated buildDir with layout.buildDirectory - Add junit-platform-launcher dependency (required by Gradle 9) Co-authored-by: jGleitz <4305652+jGleitz@users.noreply.github.com>
1 parent 8ff63b9 commit 21c982c

5 files changed

Lines changed: 27 additions & 36 deletions

File tree

base/build.gradle.kts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.gradle.api.JavaVersion.VERSION_17
2-
import org.jetbrains.kotlin.config.KotlinCompilerVersion
3-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
43

54
plugins {
65
kotlin("jvm")
@@ -16,9 +15,10 @@ dependencies {
1615
testImplementation(name = "spek-dsl-jvm", version = spekVersion, group = "org.spekframework.spek2")
1716
testImplementation(name = "atrium-fluent-en_GB", version = "0.16.0", group = "ch.tutteli.atrium")
1817
testRuntimeOnly(name = "spek-runner-junit5", version = spekVersion, group = "org.spekframework.spek2")
18+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
1919

2020
constraints {
21-
testImplementation(kotlin("reflect", version = KotlinCompilerVersion.VERSION))
21+
testImplementation(kotlin("reflect"))
2222
}
2323
}
2424

@@ -29,23 +29,20 @@ java {
2929

3030
kotlin {
3131
explicitApi()
32-
}
33-
34-
tasks.withType<KotlinCompile> {
35-
kotlinOptions {
36-
jvmTarget = "17"
37-
freeCompilerArgs += "-Xopt-in=kotlin.io.path.ExperimentalPathApi"
32+
compilerOptions {
33+
jvmTarget = JvmTarget.JVM_17
34+
freeCompilerArgs.add("-opt-in=kotlin.io.path.ExperimentalPathApi")
3835
}
3936
}
4037

4138
tasks.withType<Test> {
4239
useJUnitPlatform()
4340

44-
val testPwd = buildDir.resolve("test-pwd")
41+
val testPwd = layout.buildDirectory.dir("test-pwd")
4542
doFirst {
46-
testPwd.mkdirs()
43+
testPwd.get().asFile.mkdirs()
4744
}
48-
workingDir = testPwd
45+
workingDir = testPwd.get().asFile
4946
}
5047

5148

base/src/main/kotlin/DefaultTestFiles.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public class DefaultTestFiles: TestFiles {
159159
private val unixInvalidCharacters get() = Regex("[/\u0000]")
160160
private val windowsInvalidCharacters get() = Regex("[/\\\\<>:\"|?*\u0000]")
161161
private val invalidFileNameCharacters by lazy(PUBLICATION) {
162-
val osName = System.getProperty("os.name").toLowerCase()
162+
val osName = System.getProperty("os.name").lowercase()
163163
if (setOf("nix", "nux", "aix", "mac").any { osName.contains(it) }) unixInvalidCharacters
164164
else windowsInvalidCharacters // default to windows because it is the most restrictive
165165
}

build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
id("org.jetbrains.dokka-javadoc") version "2.1.0" apply false
77
`maven-publish`
88
signing
9-
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
9+
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
1010
idea
1111
}
1212

@@ -150,10 +150,10 @@ subprojects {
150150
tasks.register("release") {
151151
group = "release"
152152
description = "Releases the project to all remote repositories"
153-
dependsOn(publishToGithub, publishToMavenCentral, rootProject.tasks.closeAndReleaseStagingRepository)
153+
dependsOn(publishToGithub, publishToMavenCentral, rootProject.tasks.closeAndReleaseStagingRepositories)
154154
}
155155

156-
rootProject.tasks.closeAndReleaseStagingRepository { mustRunAfter(publishToMavenCentral) }
156+
rootProject.tasks.closeAndReleaseStagingRepositories { mustRunAfter(publishToMavenCentral) }
157157
}
158158
}
159159

kotest/build.gradle.kts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.gradle.api.JavaVersion.VERSION_17
2-
import org.jetbrains.kotlin.config.KotlinCompilerVersion
3-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
43

54
plugins {
65
kotlin("jvm")
@@ -19,9 +18,10 @@ dependencies {
1918

2019
testImplementation(name = "kotest-runner-junit5", version = kotestVersion, group = "io.kotest")
2120
testImplementation(name = "atrium-fluent-en_GB", version = "0.16.0", group = "ch.tutteli.atrium")
21+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
2222

2323
constraints {
24-
testImplementation(kotlin("reflect", version = KotlinCompilerVersion.VERSION))
24+
testImplementation(kotlin("reflect"))
2525
}
2626
}
2727

@@ -32,17 +32,14 @@ java {
3232

3333
kotlin {
3434
explicitApi()
35-
}
36-
37-
tasks.withType<KotlinCompile> {
38-
kotlinOptions {
39-
jvmTarget = "17"
35+
compilerOptions {
36+
jvmTarget = JvmTarget.JVM_17
4037
}
4138
}
4239

4340
tasks.compileTestKotlin {
44-
kotlinOptions {
45-
freeCompilerArgs += "-Xopt-in=kotlin.io.path.ExperimentalPathApi"
41+
compilerOptions {
42+
freeCompilerArgs.add("-opt-in=kotlin.io.path.ExperimentalPathApi")
4643
}
4744
}
4845

spek/build.gradle.kts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.gradle.api.JavaVersion.VERSION_17
2-
import org.jetbrains.kotlin.config.KotlinCompilerVersion
3-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
43

54
plugins {
65
kotlin("jvm")
@@ -21,9 +20,10 @@ dependencies {
2120
testImplementation(name = "spek-dsl-jvm", version = spekVersion, group = "org.spekframework.spek2")
2221
testImplementation(name = "atrium-fluent-en_GB", version = "0.16.0", group = "ch.tutteli.atrium")
2322
testRuntimeOnly(name = "spek-runner-junit5", version = spekVersion, group = "org.spekframework.spek2")
23+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
2424

2525
constraints {
26-
testImplementation(kotlin("reflect", version = KotlinCompilerVersion.VERSION))
26+
testImplementation(kotlin("reflect"))
2727
}
2828
}
2929

@@ -34,17 +34,14 @@ java {
3434

3535
kotlin {
3636
explicitApi()
37-
}
38-
39-
tasks.withType<KotlinCompile> {
40-
kotlinOptions {
41-
jvmTarget = "17"
37+
compilerOptions {
38+
jvmTarget = JvmTarget.JVM_17
4239
}
4340
}
4441

4542
tasks.compileTestKotlin {
46-
kotlinOptions {
47-
freeCompilerArgs += "-Xopt-in=kotlin.io.path.ExperimentalPathApi"
43+
compilerOptions {
44+
freeCompilerArgs.add("-opt-in=kotlin.io.path.ExperimentalPathApi")
4845
}
4946
}
5047

0 commit comments

Comments
 (0)