From 20784c9fe1abdd205ecbadc0151bcc53e52482f4 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Wed, 6 Nov 2024 09:28:05 +0100 Subject: [PATCH] Add Convention Plugins for Kotlin --- app/build.gradle.kts | 5 +++-- bespin/build.gradle.kts | 1 + corellia/build.gradle.kts | 1 + coruscant/build.gradle.kts | 1 + gradle.properties | 3 +++ gradle/libs.versions.toml | 2 ++ gradle/plugins/build.gradle.kts | 1 + ...rg.example.gradle.base.identity.gradle.kts | 2 +- ...mple.gradle.check.format-kotlin.gradle.kts | 6 ++++++ ...le.gradle.component.application.gradle.kts | 2 ++ ...xample.gradle.component.library.gradle.kts | 2 ++ ...e.gradle.feature.compile-kotlin.gradle.kts | 19 +++++++++++++++++++ kamino/build.gradle.kts | 1 + kashyyyk/build.gradle.kts | 1 + naboo/build.gradle.kts | 1 + tatooine/build.gradle.kts | 1 + 16 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 gradle/plugins/src/main/kotlin/org.example.gradle.check.format-kotlin.gradle.kts create mode 100644 gradle/plugins/src/main/kotlin/org.example.gradle.feature.compile-kotlin.gradle.kts diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 30c90727..88ec3f5f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,16 +11,17 @@ dependencies { implementation(projects.tatooine) implementation(libs.guice) implementation(libs.guice.servlet) + implementation(libs.kotlin.stdlib) implementation(libs.slf4j.api) runtimeOnly(libs.slf4j.simple) providedCompile(libs.jakarta.servlet.api) + mockApiApi(libs.guava) mockApiImplementation(projects.app) - mockApiImplementation(libs.guava) testImplementation(libs.junit.jupiter.api) + testEndToEndApi(libs.junit.jupiter.api) testEndToEndImplementation(projects.app) { capabilities { requireFeature("mock-api") } } testEndToEndImplementation(libs.guava) - testEndToEndImplementation(libs.junit.jupiter.api) } diff --git a/bespin/build.gradle.kts b/bespin/build.gradle.kts index e5c62a61..d70173c4 100644 --- a/bespin/build.gradle.kts +++ b/bespin/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("org.example.gradle.component.library") } dependencies { api(projects.corellia) + api(libs.kotlin.stdlib) implementation(projects.coruscant) implementation(libs.velocity.engine.core) diff --git a/corellia/build.gradle.kts b/corellia/build.gradle.kts index a3875d4c..a36f9702 100644 --- a/corellia/build.gradle.kts +++ b/corellia/build.gradle.kts @@ -4,6 +4,7 @@ plugins { } dependencies { + api(libs.kotlin.stdlib) api(libs.poi) implementation(libs.commons.io) implementation(libs.poi.ooxml) diff --git a/coruscant/build.gradle.kts b/coruscant/build.gradle.kts index 71bb66bd..2aa5bc63 100644 --- a/coruscant/build.gradle.kts +++ b/coruscant/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { api(libs.jackson.annotations) api(libs.jackson.databind) api(libs.jakarta.inject.api) + api(libs.kotlin.stdlib) api(libs.opensaml) api(libs.org.json) implementation(libs.httpcomponents.fluent.hc) diff --git a/gradle.properties b/gradle.properties index 2d9e02e4..2f8c55cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,3 +8,6 @@ org.gradle.configuration-cache=true # activate Gradle build cache - switch between branches/commits without rebuilding every time org.gradle.caching=true + +# control Kotlin standard library dependencies (and their scope) ourselves +kotlin.stdlib.default.dependency=false diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index bf943923..d05d4636 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,6 +39,8 @@ jakarta-mail-impl = { module = "com.sun.mail:jakarta.mail", version.ref = "jakar jakarta-servlet-api = { module = "jakarta.servlet:jakarta.servlet-api", version.ref = "jakarta-servlet" } jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" } junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" } +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" } +kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" } opensaml = { module = "org.opensaml:opensaml", version.ref = "opensaml" } org-json = { module = "org.json:json", version.ref = "org-json" } org-reflections = { module = "org.reflections:reflections", version.ref = "org-reflections" } diff --git a/gradle/plugins/build.gradle.kts b/gradle/plugins/build.gradle.kts index e9e5aff8..d7aa1d4a 100644 --- a/gradle/plugins/build.gradle.kts +++ b/gradle/plugins/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { implementation("io.fuchs.gradle.classpath-collision-detector:classpath-collision-detector:1.0.0") implementation("org.cyclonedx:cyclonedx-gradle-plugin:1.10.0") implementation("org.gradlex:jvm-dependency-conflict-resolution:2.1.2") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20") } testing.suites.named("test") { diff --git a/gradle/plugins/src/main/kotlin/org.example.gradle.base.identity.gradle.kts b/gradle/plugins/src/main/kotlin/org.example.gradle.base.identity.gradle.kts index be33eaaf..6f5800c5 100644 --- a/gradle/plugins/src/main/kotlin/org.example.gradle.base.identity.gradle.kts +++ b/gradle/plugins/src/main/kotlin/org.example.gradle.base.identity.gradle.kts @@ -2,7 +2,7 @@ plugins { id("org.gradle.base") } // Set the group required to refer to a Module "from outside". // I.e., when it is published or used in Included Builds. -group = "org.example.product.java" +group = "org.example.product.kotlin" // Set the version from 'version.txt' version = providers.fileContents(isolated.rootProject.projectDirectory.file("gradle/version.txt")).asText.getOrElse("") diff --git a/gradle/plugins/src/main/kotlin/org.example.gradle.check.format-kotlin.gradle.kts b/gradle/plugins/src/main/kotlin/org.example.gradle.check.format-kotlin.gradle.kts new file mode 100644 index 00000000..dc5bc9ba --- /dev/null +++ b/gradle/plugins/src/main/kotlin/org.example.gradle.check.format-kotlin.gradle.kts @@ -0,0 +1,6 @@ +plugins { + id("com.diffplug.spotless") + id("org.example.gradle.base.lifecycle") +} + +spotless { kotlin { ktfmt().kotlinlangStyle() } } diff --git a/gradle/plugins/src/main/kotlin/org.example.gradle.component.application.gradle.kts b/gradle/plugins/src/main/kotlin/org.example.gradle.component.application.gradle.kts index 6cd73278..b09e7a18 100644 --- a/gradle/plugins/src/main/kotlin/org.example.gradle.component.application.gradle.kts +++ b/gradle/plugins/src/main/kotlin/org.example.gradle.component.application.gradle.kts @@ -6,8 +6,10 @@ plugins { id("org.example.gradle.check.dependencies") id("org.example.gradle.check.format-gradle") id("org.example.gradle.check.format-java") + id("org.example.gradle.check.format-kotlin") id("org.example.gradle.feature.checksum") id("org.example.gradle.feature.compile-java") + id("org.example.gradle.feature.compile-kotlin") id("org.example.gradle.feature.javadoc") id("org.example.gradle.feature.test") id("org.example.gradle.feature.test-end-to-end") diff --git a/gradle/plugins/src/main/kotlin/org.example.gradle.component.library.gradle.kts b/gradle/plugins/src/main/kotlin/org.example.gradle.component.library.gradle.kts index 265f96df..66c89f8d 100644 --- a/gradle/plugins/src/main/kotlin/org.example.gradle.component.library.gradle.kts +++ b/gradle/plugins/src/main/kotlin/org.example.gradle.component.library.gradle.kts @@ -6,7 +6,9 @@ plugins { id("org.example.gradle.check.dependencies") id("org.example.gradle.check.format-gradle") id("org.example.gradle.check.format-java") + id("org.example.gradle.check.format-kotlin") id("org.example.gradle.feature.compile-java") + id("org.example.gradle.feature.compile-kotlin") id("org.example.gradle.feature.javadoc") id("org.example.gradle.feature.test") } diff --git a/gradle/plugins/src/main/kotlin/org.example.gradle.feature.compile-kotlin.gradle.kts b/gradle/plugins/src/main/kotlin/org.example.gradle.feature.compile-kotlin.gradle.kts new file mode 100644 index 00000000..1c5e9d3f --- /dev/null +++ b/gradle/plugins/src/main/kotlin/org.example.gradle.feature.compile-kotlin.gradle.kts @@ -0,0 +1,19 @@ +import org.gradle.jvm.toolchain.JavaLanguageVersion + +plugins { + id("org.jetbrains.kotlin.jvm") + id("org.example.gradle.base.lifecycle") +} + +kotlin { + jvmToolchain { + languageVersion = + JavaLanguageVersion.of( + providers + .fileContents(isolated.rootProject.projectDirectory.file("gradle/jdk-version.txt")) + .asText + .get() + .trim() + ) + } +} diff --git a/kamino/build.gradle.kts b/kamino/build.gradle.kts index dbc6bab8..7bf82aae 100644 --- a/kamino/build.gradle.kts +++ b/kamino/build.gradle.kts @@ -5,6 +5,7 @@ plugins { dependencies { api(projects.coruscant) + api(libs.kotlin.stdlib) api(libs.resteasy.core) implementation(libs.resteasy.guice) implementation(libs.resteasy.jackson2.provider) diff --git a/kashyyyk/build.gradle.kts b/kashyyyk/build.gradle.kts index 63630d2f..995b9753 100644 --- a/kashyyyk/build.gradle.kts +++ b/kashyyyk/build.gradle.kts @@ -3,6 +3,7 @@ plugins { id("org.example.gradle.component.library") } dependencies { api(projects.naboo) api(projects.tatooine) + api(libs.kotlin.stdlib) implementation(projects.bespin) implementation(projects.kamino) diff --git a/naboo/build.gradle.kts b/naboo/build.gradle.kts index bc93807e..4c391dd4 100644 --- a/naboo/build.gradle.kts +++ b/naboo/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("org.example.gradle.component.library") } dependencies { + api(libs.kotlin.stdlib) implementation(libs.solr.solrj) implementation(libs.zookeeper.jute) diff --git a/tatooine/build.gradle.kts b/tatooine/build.gradle.kts index 0a382204..75391a0c 100644 --- a/tatooine/build.gradle.kts +++ b/tatooine/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("org.example.gradle.component.library") } dependencies { + api(libs.kotlin.stdlib) api(libs.typesafeconfig.guice) implementation(libs.zookeeper)