Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to gradle build-logic #224

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 9 additions & 57 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
Expand All @@ -14,72 +11,26 @@ buildscript {
}

plugins {
kotlin("multiplatform") version "2.0.0"
id("org.jetbrains.dokka") version "1.9.20"
val tutteliGradleVersion = "5.0.1"
id("ch.tutteli.gradle.plugins.dokka") version tutteliGradleVersion
id("ch.tutteli.gradle.plugins.junitjacoco") version tutteliGradleVersion
id("ch.tutteli.gradle.plugins.kotlin.module.info") version tutteliGradleVersion
id("ch.tutteli.gradle.plugins.publish") version tutteliGradleVersion
id("io.gitlab.arturbosch.detekt") version "1.23.6"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("build-logic.published-kotlin-multiplatform")
alias(libs.plugins.detekt)
alias(libs.plugins.nexus.publish)
}
val atriumVersion by extra("1.2.0")

the<ch.tutteli.gradle.plugins.junitjacoco.JunitJacocoPluginExtension>()
.allowedTestTasksWithoutTests.set(listOf("jsNodeTest"))

repositories { mavenCentral() }

kotlin {
compilerOptions {
@Suppress("DEPRECATION" /* we support kotlin 1.4 as long as possible */)
val kotlinVersion = KotlinVersion.KOTLIN_1_4
apiVersion.set(kotlinVersion)
languageVersion.set(kotlinVersion)
freeCompilerArgs.add("-Xexpect-actual-classes")
}

jvm { withJava() }
js(IR) { nodejs() }

sourceSets {
val excludeKbox: ExternalModuleDependency.() -> Unit = {
exclude(group = "ch.tutteli.kbox")
}

val commonTest by getting {
commonTest {
dependencies {
implementation(kotlin("test"))
implementation("ch.tutteli.atrium:atrium-fluent:$atriumVersion", excludeKbox)
implementation(libs.atrium.fluent.get().let { "${it.module}:${it.version}"}) {
exclude(group = "ch.tutteli.kbox")
}
}
}
}
}
kotlin {
// reading JAVA_VERSION from env to enable jdk17 build in CI
val jdkVersion = System.getenv("JAVA_VERSION")?.toIntOrNull() ?: 11
jvmToolchain(jdkVersion)
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
tasks.withType<JavaCompile> {
sourceCompatibility = "11"
targetCompatibility = "11"
}
tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
with(freeCompilerArgs) {
add("-opt-in=kotlin.RequiresOptIn")
add("-Xexpect-actual-classes")
}
}
}

detekt {
allRules = true
config.from(files("${rootProject.projectDir}/gradle/scripts/detekt.yml"))
config.from(files("${rootProject.projectDir}/gradle/detekt.yml"))
}

val detektTasks = tasks.withType<io.gitlab.arturbosch.detekt.Detekt>()
Expand Down Expand Up @@ -126,6 +77,7 @@ nexusPublishing {
}
}


/*

Release & deploy a commit
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
kotlin.code.style=official
kotlin.js.generate.executable.default=false

# com.github.vlsi.gradle-extensions prints only failing or slow test results
slowTestLogThreshold=500
slowSuiteLogThreshold=5000
17 changes: 17 additions & 0 deletions gradle/build-logic-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion

plugins {
`kotlin-dsl`
}

allprojects {
group = "ch.tutteli.kbox.build-logic.convention"
}

dependencies {
// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files,
// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin
// in order to be able to specify tasks.validatePlugins
// See https://github.com/gradle/gradle/issues/17016 regarding expectedKotlinDslPluginsVersion
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
}
8 changes: 8 additions & 0 deletions gradle/build-logic-conventions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
gradlePluginPortal()
}
}

rootProject.name = "build-logic-conventions"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("org.gradle.kotlin.kotlin-dsl") // this is 'kotlin-dsl' without version
}

tasks.validatePlugins {
failOnWarning.set(true)
enableStricterValidation.set(true)
}
10 changes: 10 additions & 0 deletions gradle/build-logic/basics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
api(projects.buildParameters)
api(buildLibs.vlsi.crlf)
api(buildLibs.vlsi.gradle)
api(buildLibs.taskTree)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
// plugins we use in all gradle projects
id("build-logic.build-params")
id("com.github.vlsi.gradle-extensions")
// enable to analyse task dependencies
// id("com.dorongold.task-tree")
}
7 changes: 7 additions & 0 deletions gradle/build-logic/basics/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.gradle.api.DomainObjectCollection
import org.gradle.kotlin.dsl.withType

// TODO check if already moved into own tegonal repo and fetch via gt
// copied from com.github.vlsi.gradle.dsl.configureEach, using this instead so that we don't have to import
inline fun <reified S : Any> DomainObjectCollection<in S>.configureEach(noinline configuration: S.() -> Unit) =
withType().configureEach(configuration)
47 changes: 47 additions & 0 deletions gradle/build-logic/build-parameters/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
alias(buildLibs.plugins.build.parameters)
}

buildParameters {
pluginId("build-logic.build-params")

// Other plugins can contribute parameters, so below list is not exhaustive, hence we disable the validation
enableValidation.set(false)

val defaultJdkVersion = 11
integer("defaultJdkVersion") {
defaultValue.set(defaultJdkVersion)
mandatory.set(true)
description.set("Default jdk version for source and target compatibility")
}

group("kotlin") {
string("version") {
fromEnvironment()
@Suppress("DEPRECATION" /* we support kotlin_1_4 on purpose */)
defaultValue.set(KotlinVersion.KOTLIN_1_4.version)
description.set("kotlin version used for apiVersion and languageVersion")
}
bool("werror") {
defaultValue.set(true)
description.set("Treat kotlinc warnings as errors")
}
}


group("java") {
integer("version") {
fromEnvironment()
defaultValue.set(defaultJdkVersion)
description.set("Java version used for java.toolchain")
}
bool("werror") {
defaultValue.set(true)
description.set("Treat javac, javadoc, warnings as errors")
}
}

}
7 changes: 7 additions & 0 deletions gradle/build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`embedded-kotlin` apply false
}

allprojects {
group = "ch.tutteli.kbox.build-logic"
}
12 changes: 12 additions & 0 deletions gradle/build-logic/dev/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
api(projects.basics)

api(buildLibs.kotlin)
api(buildLibs.bundles.dokka)
api(buildLibs.tutteli.junitjacoco)
api(buildLibs.tutteli.moduleinfo)
}
9 changes: 9 additions & 0 deletions gradle/build-logic/dev/src/main/kotlin/DokkaExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.AbstractDokkaTask

fun AbstractDokkaTask.configurePlugins() {
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
footerMessage = "KBox &copy; Copyright Robert Stoll &lt;[email protected]&gt;"
}
}
29 changes: 29 additions & 0 deletions gradle/build-logic/dev/src/main/kotlin/build-logic.java.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id("java")
id("build-logic.gradle-conventions")
}

java {
toolchain {
// reading JAVA_VERSION from env to enable jdk17 build in CI
languageVersion.set(JavaLanguageVersion.of(buildParameters.java.version))
}
consistentResolution {
useCompileClasspathVersions()
}
}


tasks.configureEach<JavaCompile> {
inputs.property("java.version", System.getProperty("java.version"))
inputs.property("java.vm.version", System.getProperty("java.vm.version"))
sourceCompatibility = buildParameters.defaultJdkVersion.toString()
targetCompatibility = buildParameters.defaultJdkVersion.toString()
options.apply {
encoding = "UTF-8"
compilerArgs.add("-Xlint:deprecation")
if (buildParameters.java.werror) {
compilerArgs.add("-Werror")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("ch.tutteli.gradle.plugins.junitjacoco")
}

dependencies {
// used to run the samples
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("build-logic.gradle-conventions")
}
tasks.configureEach<KotlinCompilationTask<*>> {
compilerOptions {
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
// suppress warnings about kotlin 1.4 being deprecated
freeCompilerArgs.add("-Xsuppress-version-warnings")
// suppress warnings about expect/actual being an experimental feature
freeCompilerArgs.add("-Xexpect-actual-classes")

val kotlinVersion = KotlinVersion.fromVersion(buildParameters.kotlin.version)
languageVersion.set(kotlinVersion)
apiVersion.set(kotlinVersion)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("build-logic.kotlin-conventions")
id("build-logic.junit-jacoco-conventions")
// this plugin sets inter alia toolchain and source/targetCompatibility
// but also applies common plugins such as gradle-convention, build-params
id("build-logic.java")
id("ch.tutteli.gradle.plugins.kotlin.module.info")
}

tasks.configureEach<KotlinCompile> {
compilerOptions{
jvmTarget.set(JvmTarget.fromTarget(buildParameters.defaultJdkVersion.toString()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
kotlin("jvm")
id("build-logic.kotlin-jvm-conventions")
}

dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
kotlin("multiplatform")
id("build-logic.kotlin-jvm-conventions")
}


kotlin {
jvm {
// for module-info.java
withJava()
}

js(IR) { nodejs() }

sourceSets {
commonTest {
dependencies {
implementation(kotlin("test"))
}
}

// necessary due to https://youtrack.jetbrains.com/issue/KT-65352/KMP-Gradle-impossible-to-set-language-apiVersion-for-common-to-1.4
all {
languageSettings {
languageVersion = buildParameters.kotlin.version
apiVersion = buildParameters.kotlin.version
}
}
}
}

// this is necessary due to some crazy kotlin plugin voodoo. If we define this in the rootProject itself,
// then it does not work.
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
rootProject.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
lockFileDirectory = rootProject.projectDir.resolve("gradle")
}
}
12 changes: 12 additions & 0 deletions gradle/build-logic/publishing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("build-logic.kotlin-dsl-gradle-plugin")
}

dependencies {
api(projects.basics)
api(projects.dev)

api(buildLibs.bundles.dokka)
api(buildLibs.tutteli.dokka)
api(buildLibs.tutteli.publish)
}
Loading
Loading