Skip to content

Commit

Permalink
Use libs.versions.toml and clean gradle files
Browse files Browse the repository at this point in the history
Declaring the version catalog in libs.versions.toml instead of
settings.gradle.kts has the advantage that it can be reused in buildSrc.
It also introduces a single place to define dependencies and their
version.

General cleanup of gradle files was also done, including:

 * using default output for dokka: relying on defaults means less config
   and maintenance burden

 * removing DocsTask because it was unused, last usage of this custom
   task was removed in kordlib#367

 * getting rid of the source set workaround introduced in kordlib#386 by moving
   TweetNaclFast from voice/src/main/kotlin to voice/src/main/java
  • Loading branch information
lukellmann committed Nov 12, 2022
1 parent 3298e4b commit e721794
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 273 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Push docs to gh-pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dokka
folder: build/dokka/htmlMultiModule
branch: gh-pages
git-config-name: GitHub Actions
git-config-email: [email protected]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
.gradle/
.idea/
out/
dokka/

**/build/*
!**/build/generated/
Expand Down
Empty file removed api/kord.api
Empty file.
43 changes: 7 additions & 36 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType.ALL

@Suppress("DSL_SCOPE_VIOLATION") // false positive for `libs` in IntelliJ
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.1"
id("org.jetbrains.dokka")
org.jetbrains.dokka

signing
`maven-publish`
id("io.codearte.nexus-staging") version "0.30.0"
alias(libs.plugins.nexusStaging)
}

repositories {
Expand All @@ -18,35 +16,8 @@ repositories {
group = Library.group
version = Library.version

tasks {
wrapper {
// Steps for upgrading Gradle:
// 1. update `gradleVersion` and `distributionSha256Sum`
// (use 'Complete (-all) ZIP Checksum' found here: https://gradle.org/release-checksums/)
// 2. run `./gradlew wrapper`
// (will update 'gradle/wrapper/gradle-wrapper.properties')
// 3. run `./gradlew wrapper` again
// (might update 'gradle/wrapper/gradle-wrapper.jar', 'gradlew' and 'gradlew.bat')
// 4. commit all changes

gradleVersion = "7.5.1"
distributionType = ALL
distributionSha256Sum = "db9c8211ed63f61f60292c69e80d89196f9eb36665e369e7f00ac4cc841c2219"
}

val dokkaOutputDir = rootProject.projectDir.resolve("dokka")

clean {
delete(dokkaOutputDir)
}

dokkaHtmlMultiModule {
dependsOn(clean)
failOnWarning.set(true)
outputDirectory.set(dokkaOutputDir)
}
}

apiValidation {
ignoredProjects += listOf("ksp-annotations", "ksp-processors")
tasks.wrapper {
gradleVersion = libs.versions.gradle.get()
distributionType = ALL
distributionSha256Sum = libs.versions.gradleChecksum.get()
}
9 changes: 1 addition & 8 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ plugins {

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
val kotlinVersion = "1.7.20"
implementation(kotlin("gradle-plugin", kotlinVersion))
implementation(kotlin("serialization", kotlinVersion))
implementation("org.jetbrains.dokka", "dokka-gradle-plugin", "1.7.20")
implementation("org.jetbrains.kotlinx", "atomicfu-gradle-plugin", "0.18.5")
implementation("com.google.devtools.ksp", "symbol-processing-gradle-plugin", "1.7.20-1.0.8")
implementation(gradleApi())
implementation(libs.bundles.pluginsForBuildSrc)
}
12 changes: 9 additions & 3 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
// avoids warning:
// "Project accessors enabled, but root project name not explicitly set for 'buildSrc'. Checking out the project in
// different folders will impact the generated code and implicitly the buildscript classpath, breaking caching."
rootProject.name = "buildSrc"

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
18 changes: 0 additions & 18 deletions buildSrc/src/main/kotlin/Publishing.kt

This file was deleted.

2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kord-internal-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
org.jetbrains.kotlin.jvm
}

repositories {
Expand Down
19 changes: 12 additions & 7 deletions buildSrc/src/main/kotlin/kord-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL

plugins {
java
kotlin("jvm")
kotlin("plugin.serialization")
id("org.jetbrains.dokka")
id("kotlinx-atomicfu")
id("com.google.devtools.ksp")
org.jetbrains.kotlin.jvm
org.jetbrains.kotlin.plugin.serialization
org.jetbrains.dokka
`kotlinx-atomicfu`
org.jetbrains.kotlinx.`binary-compatibility-validator`
com.google.devtools.ksp
`maven-publish`
}

repositories {
mavenCentral()
maven(url = "https://oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
Expand All @@ -34,6 +33,12 @@ kotlin {
}
}

// https://github.com/Kotlin/kotlinx-atomicfu/issues/210
atomicfu {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependenciesVersion = libs.findVersion("kotlinx-atomicfu").get().requiredVersion
}

tasks {
withType<JavaCompile> {
sourceCompatibility = Jvm.targetString
Expand Down
98 changes: 48 additions & 50 deletions buildSrc/src/main/kotlin/kord-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,71 @@ plugins {
signing
}

tasks {
publishing {
publications {
create<MavenPublication>(Library.name) {
groupId = Library.group
artifactId = "kord-${project.name}"
version = Library.version
publishing {
publications {
create<MavenPublication>(Library.name) {
groupId = Library.group
artifactId = "kord-${project.name}"
version = Library.version

pom {
name.set(Library.name)
description.set(Library.description)
url.set(Library.projectUrl)
pom {
name.set(Library.name)
description.set(Library.description)
url.set(Library.projectUrl)

organization {
name.set("Kord")
url.set("https://github.com/kordlib")
}
organization {
name.set("Kord")
url.set("https://github.com/kordlib")
}

developers {
developer {
name.set("The Kord Team")
}
developers {
developer {
name.set("The Kord Team")
}
}

issueManagement {
system.set("GitHub")
url.set("https://github.com/kordlib/kord/issues")
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/kordlib/kord/issues")
}

licenses {
license {
name.set("MIT")
url.set("http://opensource.org/licenses/MIT")
}
}
scm {
connection.set("scm:git:ssh://github.com/kordlib/kord.git")
developerConnection.set("scm:git:ssh://[email protected]:kordlib/kord.git")
url.set(Library.projectUrl)
licenses {
license {
name.set("MIT")
url.set("http://opensource.org/licenses/MIT")
}
}

if (!isJitPack) {
repositories {
maven {
url = if (Library.isSnapshot) uri(Repo.snapshotsUrl)
else uri(Repo.releasesUrl)
scm {
connection.set("scm:git:ssh://github.com/kordlib/kord.git")
developerConnection.set("scm:git:ssh://[email protected]:kordlib/kord.git")
url.set(Library.projectUrl)
}
}

credentials {
username = System.getenv("NEXUS_USER")
password = System.getenv("NEXUS_PASSWORD")
}
if (!isJitPack) {
repositories {
maven {
url = uri(if (Library.isSnapshot) Repo.snapshotsUrl else Repo.releasesUrl)

credentials {
username = System.getenv("NEXUS_USER")
password = System.getenv("NEXUS_PASSWORD")
}
}
}
}
}
}
}

if (!isJitPack && Library.isRelease) {
signing {
val signingKey = findProperty("signingKey")?.toString()
val signingPassword = findProperty("signingPassword")?.toString()
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(String(Base64.getDecoder().decode(signingKey)), signingPassword)
}
sign(publishing.publications[Library.name])
if (!isJitPack && Library.isRelease) {
signing {
val signingKey = findProperty("signingKey")?.toString()
val signingPassword = findProperty("signingPassword")?.toString()
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(String(Base64.getDecoder().decode(signingKey)), signingPassword)
}
sign(publishing.publications[Library.name])
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kord-sampled-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("jvm")
org.jetbrains.kotlin.jvm
}

sourceSets {
Expand Down
21 changes: 8 additions & 13 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
buildscript {
repositories {
mavenCentral()
}
}

@Suppress("DSL_SCOPE_VIOLATION") // false positive for `libs` in IntelliJ
plugins {
`kord-module`
`kord-sampled-module`
`kord-publishing`

// see https://github.com/gmazzo/gradle-buildconfig-plugin
id("com.github.gmazzo.buildconfig") version "3.1.0"
alias(libs.plugins.buildconfig)
}

dependencies {
api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.serialization.json)
api(libs.kotlinx.datetime)

api(libs.bundles.common)
testImplementation(libs.bundles.test.implementation)
testRuntimeOnly(libs.bundles.test.runtime)
api(libs.kotlin.logging)

compileOnly(projects.kspAnnotations)
ksp(projects.kspProcessors)

testImplementation(libs.bundles.test.implementation)
testRuntimeOnly(libs.bundles.test.runtime)
}

/*
Expand Down
4 changes: 1 addition & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ dependencies {
"voiceApi"(projects.core)
"voiceApi"(projects.voice)

implementation(libs.bundles.common)

api(libs.kord.cache.api)
api(libs.kord.cache.map)

samplesImplementation(libs.slf4j.simple)
testImplementation(libs.mockk)

testImplementation(libs.bundles.test.implementation)
testRuntimeOnly(libs.bundles.test.runtime)
}
Expand Down
5 changes: 1 addition & 4 deletions gateway/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ plugins {

dependencies {
api(projects.common)
implementation(libs.bundles.common)

api(libs.ktor.client.json)
api(libs.ktor.client.websockets)
api(libs.bundles.ktor.client.serialization)
api(libs.ktor.client.websockets)
api(libs.ktor.client.cio)


testImplementation(libs.bundles.test.implementation)
testRuntimeOnly(libs.bundles.test.runtime)
}
Loading

0 comments on commit e721794

Please sign in to comment.