Skip to content

Commit

Permalink
Upgrade to Gradle 8.0
Browse files Browse the repository at this point in the history
The changes in gradle-wrapper.jar, gradle-wrapper.properties and gradlew
are the result of running this command twice:
./gradlew wrapper --gradle-version 8.0 --gradle-distribution-sha256-sum
f30b29580fe11719087d698da23f3b0f0d04031d8995f7dd8275a31f7674dc01

While touching the build files, the following was also done:

 * use Java toolchains, see
   https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support

 * use the new compilerOptions DSL introduced in Kotlin 1.8.0, see
   https://kotlinlang.org/docs/whatsnew18.html#exposing-kotlin-compiler-options-as-gradle-lazy-properties

Running the dokkaHtmlMultiModule task is not possible with Dokka 1.7.20
and Gradle 8.0 due to Kotlin/dokka#2796. This
will prevent us from publishing Dokka docs until a fix is released.
  • Loading branch information
lukellmann committed Feb 15, 2023
1 parent ca0462d commit e8acb25
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 55 deletions.
1 change: 0 additions & 1 deletion buildSrc/settings.gradle.kts
@@ -1,7 +1,6 @@
rootProject.name = "buildSrc"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
Expand Down
13 changes: 5 additions & 8 deletions buildSrc/src/main/kotlin/Compiler.kt
@@ -1,4 +1,4 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions

object CompilerArguments {
const val time = "-opt-in=kotlin.time.ExperimentalTime"
Expand All @@ -12,13 +12,10 @@ object CompilerArguments {
}

object Jvm {
// keep these equivalent
const val targetString = "1.8"
const val targetInt = 8
const val target = 8
}

fun KotlinJvmOptions.applyKordKotlinOptions() {
jvmTarget = Jvm.targetString
allWarningsAsErrors = true
freeCompilerArgs += CompilerArguments.progressive
fun KotlinJvmCompilerOptions.applyKordCompilerOptions() {
allWarningsAsErrors.set(true)
freeCompilerArgs.add(CompilerArguments.progressive)
}
15 changes: 6 additions & 9 deletions buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Expand Up @@ -8,15 +8,12 @@ repositories {
mavenCentral()
}

tasks {
withType<JavaCompile> {
sourceCompatibility = Jvm.targetString
targetCompatibility = Jvm.targetString
}
kotlin {
jvmToolchain(Jvm.target)
}

withType<KotlinCompile> {
kotlinOptions {
applyKordKotlinOptions()
}
tasks.withType<KotlinCompile> {
compilerOptions {
applyKordCompilerOptions()
}
}
58 changes: 29 additions & 29 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
@@ -1,3 +1,4 @@
import com.google.devtools.ksp.gradle.KspTask
import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL
Expand All @@ -19,6 +20,8 @@ repositories {
kotlin {
explicitApi()

jvmToolchain(Jvm.target)

sourceSets {
// mark ksp src dir
main { kotlin.srcDir("build/generated/ksp/main/kotlin") }
Expand All @@ -34,16 +37,14 @@ atomicfu {
dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
}

tasks {
withType<JavaCompile> {
sourceCompatibility = Jvm.targetString
targetCompatibility = Jvm.targetString
}
// the kspKotlin Task is created very late and isn't available via tasks.findByName("kspKotlin")
val kspKotlin get() = tasks.withType<KspTask>().matching { it.name == "kspKotlin" }

tasks {
withType<KotlinCompile> {
kotlinOptions {
applyKordKotlinOptions()
freeCompilerArgs += listOf(
compilerOptions {
applyKordCompilerOptions()
freeCompilerArgs.addAll(
CompilerArguments.time,
CompilerArguments.contracts,

Expand All @@ -63,14 +64,14 @@ tasks {
withType<AbstractDokkaLeafTask> {
// see https://kotlin.github.io/dokka/<dokka version>/user_guide/gradle/usage/#configuration-options

// make sure ksp generates files before building docs
dependsOn(compileKotlin)
// include documentation generated by ksp
dependsOn(kspKotlin)

failOnWarning.set(true)

dokkaSourceSets.configureEach {

jdkVersion.set(Jvm.targetInt)
jdkVersion.set(Jvm.target)

val baseRemoteUrl =
"https://github.com/kordlib/kord/blob/${Library.commitHashOrDefault("0.8.x")}/${project.name}"
Expand Down Expand Up @@ -106,28 +107,27 @@ tasks {
}
}

val sourcesJar by registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
withType<PublishToMavenRepository> {
doFirst { require(!Library.isUndefined) { "No release/snapshot version found." } }
}

val dokkaJar by registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(dokkaHtml)
dependsOn(dokkaHtml)
kotlinSourcesJar {
// include sources generated by ksp
dependsOn(kspKotlin)
}
}

withType<PublishToMavenRepository>().configureEach {
doFirst { require(!Library.isUndefined) { "No release/snapshot version found." } }
}
val dokkaJar by tasks.registering(Jar::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
from(tasks.dokkaHtml)
}

publishing {
publications.withType<MavenPublication> {
from(components["java"])
artifact(sourcesJar.get())
artifact(dokkaJar.get())
}
publishing {
publications.withType<MavenPublication> {
from(components["java"])
artifact(tasks.kotlinSourcesJar)
artifact(dokkaJar)
}
}
4 changes: 0 additions & 4 deletions gradle.properties
Expand Up @@ -6,7 +6,3 @@ kotlin.code.style=official
# https://github.com/Kotlin/kotlinx-atomicfu#atomicfu-compiler-plugin
kotlinx.atomicfu.enableJvmIrTransformation=true
kotlinx.atomicfu.enableJsIrTransformation=true

# remove when upgrading to gradle 8.0
# https://docs.gradle.org/7.6/userguide/upgrading_version_7.html#strict-kotlin-dsl-precompiled-scripts-accessors
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict=true
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=312eb12875e1747e05c2f81a4789902d7e4ec5defbd1eefeaccc08acf096505d
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
distributionSha256Sum=f30b29580fe11719087d698da23f3b0f0d04031d8995f7dd8275a31f7674dc01
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down

0 comments on commit e8acb25

Please sign in to comment.