Skip to content

Commit

Permalink
Upgrade to Gradle 8.0 (#755)
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

 * use configureEach {} configuration avoidance API,
   withType<TaskType> { ... } creates tasks eagerly and should be
   replaced by withType<TaskType>().configureEach { ... },  see
   https://docs.gradle.org/current/userguide/task_configuration_avoidance.html#sec:old_vs_new_configuration_api_overview

Co-authored-by: Michael Rittmeister <michael@rittmeister.in>
  • Loading branch information
lukellmann and DRSchlaubi committed Feb 16, 2023
1 parent 2cab7f3 commit 142a950
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 63 deletions.
4 changes: 2 additions & 2 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
constraints {
rootProject.subprojects.forEach { subproject ->
if (subproject.plugins.hasPlugin("maven-publish") && subproject.name != name) {
subproject.publishing.publications.withType<MavenPublication> {
subproject.publishing.publications.withType<MavenPublication>().configureEach {
if (!artifactId.endsWith("-metadata") &&
!artifactId.endsWith("-kotlinMultiplatform")
) {
Expand All @@ -27,7 +27,7 @@ dependencies {
}

publishing {
publications.withType<MavenPublication> {
publications.withType<MavenPublication>().configureEach {
from(components["javaPlatform"])
}
}
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ plugins {

repositories {
mavenCentral()
// until Dokka 1.8.0 is released and we no longer need dev builds, see https://github.com/kordlib/kord/pull/755
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
}

group = Library.group
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {

repositories {
mavenCentral()
// until Dokka 1.8.0 is released and we no longer need dev builds, see https://github.com/kordlib/kord/pull/755
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
}

dependencies {
Expand Down
1 change: 0 additions & 1 deletion buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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>().configureEach {
compilerOptions {
applyKordCompilerOptions()
}
}
66 changes: 35 additions & 31 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 @@ -14,11 +15,15 @@ plugins {

repositories {
mavenCentral()
// until Dokka 1.8.0 is released and we no longer need dev builds, see https://github.com/kordlib/kord/pull/755
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
}

kotlin {
explicitApi()

jvmToolchain(Jvm.target)

sourceSets {
// mark ksp src dir
main { kotlin.srcDir("build/generated/ksp/main/kotlin") }
Expand All @@ -35,15 +40,10 @@ atomicfu {
}

tasks {
withType<JavaCompile> {
sourceCompatibility = Jvm.targetString
targetCompatibility = Jvm.targetString
}

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

Expand All @@ -54,23 +54,28 @@ tasks {
}
}

withType<Test> {
withType<Test>().configureEach {
useJUnitPlatform()
}

fun Task.dependsOnKspKotlin() {
val kspKotlin = findByName("kspKotlin")
if (kspKotlin != null) dependsOn(kspKotlin)
}

// configure both dokkaHtml and dokkaHtmlPartial tasks
// (dokkaHtmlMultiModule depends on dokkaHtmlPartial, dokkaJar depends on dokkaHtml)
withType<AbstractDokkaLeafTask> {
withType<AbstractDokkaLeafTask>().configureEach {
// 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
dependsOnKspKotlin()

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 +111,27 @@ tasks {
}
}

val sourcesJar by registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
withType<PublishToMavenRepository>().configureEach {
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
dependsOnKspKotlin()
}
}

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>().configureEach {
from(components["java"])
artifact(tasks.kotlinSourcesJar)
artifact(dokkaJar)
}
}
7 changes: 4 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ plugins {
`kord-publishing`
}

val voice by sourceSets.creating
val voice: SourceSet by sourceSets.creating
val voiceApi: Configuration by configurations.getting

configurations {
getByName("voiceImplementation") {
Expand All @@ -17,8 +18,8 @@ dependencies {
api(projects.common)
api(projects.rest)
api(projects.gateway)
"voiceApi"(projects.core)
"voiceApi"(projects.voice)
voiceApi(projects.core)
voiceApi(projects.voice)

api(libs.kord.cache.api)
api(libs.kord.cache.map)
Expand Down
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mockk = "1.13.2" # https://github.com/mockk/mockk
slf4j = "1.7.36" # https://www.slf4j.org

# plugins
dokka = "1.7.20" # https://github.com/Kotlin/dokka
dokka = "1.8.0-dev-194" # https://github.com/Kotlin/dokka
kotlinx-atomicfu = "0.19.0" # https://github.com/Kotlin/kotlinx-atomicfu
binary-compatibility-validator = "0.12.1" # https://github.com/Kotlin/binary-compatibility-validator
buildconfig = "3.1.0" # https://github.com/gmazzo/gradle-buildconfig-plugin
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 142a950

Please sign in to comment.