Skip to content

Commit

Permalink
Build logic cleanup
Browse files Browse the repository at this point in the history
* align build-logic plugins with Gradle suggestions;
* introduce build-logic-settings for multiple settings configuration;
* move kotlin version to Version Catalog;
* move build-logic to root of the project;
* remove build-parameters;
* rename build-logic plugins;
* minor cleanup in the publication script;
* drop target-specific convention plugins, as KGP now generates; accessors;
* use targets helpers in projects;
* drop template convention plugins;
* create test aggregate tasks;
* reduce usages of OptIns;
* use jvm-default=all (easier compatibility in future);
* drop test server completely for now from `rsocket-transport-tests`;
* Update some Gradle properties;
* implement small DSL for including projects;
  • Loading branch information
whyoleg committed Apr 15, 2024
1 parent 77a8279 commit ec8442c
Show file tree
Hide file tree
Showing 53 changed files with 832 additions and 1,054 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ jobs:
--scan
--info
--continue
-Pskip.test
-Prsocketbuild.skipTests=true
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,10 +18,6 @@ plugins {
`kotlin-dsl`
}

kotlin {
jvmToolchain(8)
}

dependencies {
implementation("rsocket.build:build-parameters")
implementation(libs.kotlin.gradle.plugin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,30 +15,19 @@
*/

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
includeBuild("../kotlin-version-catalog")
includeBuild("../build-settings")
}

dependencyResolutionManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
plugins {
id("rsocketsettings.default")
}

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../libs.versions.toml"))
from(files("../gradle/libs.versions.toml"))
}
}
}

plugins {
id("kotlin-version-catalog")
}

rootProject.name = "build-logic"

includeBuild("../build-parameters")
133 changes: 133 additions & 0 deletions build-logic/src/main/kotlin/rsocketbuild.multiplatform-base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.jetbrains.kotlin.gradle.*
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.targets.js.ir.*
import org.jetbrains.kotlin.gradle.targets.jvm.*
import org.jetbrains.kotlin.gradle.targets.jvm.tasks.*
import org.jetbrains.kotlin.gradle.targets.native.tasks.*
import org.jetbrains.kotlin.gradle.tasks.*
import rsocketbuild.*
import rsocketbuild.tests.*

plugins {
kotlin("multiplatform")
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
compilerOptions {
// because of https://youtrack.jetbrains.com/issue/KT-64115/KGP-JVM-JS-WASM-The-same-library-can-be-passed-twice-to-the-compiler
// allWarningsAsErrors.set(true)
progressiveMode.set(true)
freeCompilerArgs.add("-Xrender-internal-diagnostic-names")
}

sourceSets.configureEach {
languageSettings {
if (name.contains("test", ignoreCase = true)) {
optIn(OptIns.ExperimentalStdlibApi)
optIn(OptIns.DelicateCoroutinesApi)

// rsocket related
optIn(OptIns.TransportApi)
optIn(OptIns.ExperimentalMetadataApi)
optIn(OptIns.ExperimentalStreamsApi)
optIn(OptIns.RSocketLoggingApi)
}
}
}

targets.withType<KotlinJvmTarget>().configureEach {
compilations.configureEach {
compilerOptions.configure {
freeCompilerArgs.add("-Xjvm-default=all")
}
}
}

// revisit JS block after WASM support
targets.withType<KotlinJsIrTarget>().configureEach {
whenBrowserConfigured {
testTask {
useKarma {
useConfigDirectory(rootDir.resolve("gradle/js/karma.config.d"))
useChromeHeadless()
}
}
}
whenNodejsConfigured {
testTask {
useMocha {
timeout = "600s"
}
}
}
}

//setup tests running in RELEASE mode
targets.withType<KotlinNativeTarget>().configureEach {
binaries.test(listOf(NativeBuildType.RELEASE))
}
targets.withType<KotlinNativeTargetWithTests<*>>().configureEach {
testRuns.create("releaseTest") {
setExecutionSourceFrom(binaries.getTest(NativeBuildType.RELEASE))
}
}
}

// for CI mainly

registerTestAggregationTask(
name = "jvmAllTest",
taskDependencies = { tasks.withType<KotlinJvmTest>() },
targetFilter = { it.platformType == KotlinPlatformType.jvm }
)

registerTestAggregationTask(
name = "nativeTest",
taskDependencies = { tasks.withType<KotlinNativeTest>().matching { it.enabled } },
targetFilter = { it.platformType == KotlinPlatformType.native }
)

listOf("ios", "watchos", "tvos", "macos").forEach { targetGroup ->
registerTestAggregationTask(
name = "${targetGroup}Test",
taskDependencies = {
tasks.withType<KotlinNativeTest>().matching {
it.enabled && it.name.startsWith(targetGroup, ignoreCase = true)
}
},
targetFilter = {
it.platformType == KotlinPlatformType.native && it.name.startsWith(targetGroup, ignoreCase = true)
}
)
}

// on build, link even those binaries, which it's not possible to run
tasks.build {
dependsOn(tasks.withType<KotlinNativeLink>())
}

if (providers.gradleProperty("rsocketbuild.skipTests").map(String::toBoolean).getOrElse(false)) {
tasks.withType<AbstractTestTask>().configureEach { onlyIf { false } }
}

if (providers.gradleProperty("rsocketbuild.skipNativeLink").map(String::toBoolean).getOrElse(false)) {
tasks.withType<KotlinNativeLink>().configureEach { onlyIf { false } }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2023 the original author or authors.
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,9 +15,10 @@
*/

plugins {
id("rsocket.target.native.apple")
id("rsocketbuild.multiplatform-base")
id("rsocketbuild.publication")
}

kotlin {
linuxX64()
explicitApi()
}
109 changes: 109 additions & 0 deletions build-logic/src/main/kotlin/rsocketbuild.publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
`maven-publish`
signing
}

val githubUsername: String? by project
val githubPassword: String? by project

val sonatypeUsername: String? by project
val sonatypePassword: String? by project

val signingKey: String? by project
val signingPassword: String? by project

// TODO: refactor publication a bit, so that version in gradle.properties will not contain SNAPSHOT
val versionSuffix = providers.gradleProperty("rsocketbuild.versionSuffix").orNull
if (versionSuffix != null) {
val versionString = project.version.toString()
require(versionString.endsWith("-SNAPSHOT"))
project.version = versionString.replace("-", "-${versionSuffix}-")
println("Current version: ${project.version}")
}

// empty javadoc for maven central
val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") }

// this is somewhat a hack because we have a single javadoc artifact which is used for all publications
tasks.withType<Sign>().configureEach { mustRunAfter(javadocJar) }
tasks.withType<AbstractPublishToMaven>().configureEach { mustRunAfter(tasks.withType<Sign>()) }

publishing {
publications.withType<MavenPublication> {
artifact(javadocJar)
pom {
name.set(project.name)
description.set(provider {
checkNotNull(project.description) { "Project description isn't set for project: ${project.path}" }
})
url.set("http://rsocket.io")

licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("whyoleg")
name.set("Oleg Yukhnevich")
email.set("whyoleg@gmail.com")
}
developer {
id.set("OlegDokuka")
name.set("Oleh Dokuka")
email.set("oleh.dokuka@icloud.com")
}
}
scm {
connection.set("https://github.com/rsocket/rsocket-kotlin.git")
developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git")
url.set("https://github.com/rsocket/rsocket-kotlin")
}
}
}

repositories {
// TODO: drop github and use sonatype (?)
maven {
name = "github"
url = uri("https://maven.pkg.github.com/rsocket/rsocket-kotlin")
credentials {
username = githubUsername
password = githubPassword
}
}
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}
}

signing {
isRequired = sonatypeUsername != null && sonatypePassword != null
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications)
}
29 changes: 29 additions & 0 deletions build-logic/src/main/kotlin/rsocketbuild/OptIns.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2015-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package rsocketbuild

@Suppress("ConstPropertyName")
object OptIns {
const val ExperimentalStdlibApi = "kotlin.ExperimentalStdlibApi"
const val ExperimentalCoroutinesApi = "kotlinx.coroutines.ExperimentalCoroutinesApi"
const val DelicateCoroutinesApi = "kotlinx.coroutines.DelicateCoroutinesApi"

const val TransportApi = "io.rsocket.kotlin.TransportApi"
const val ExperimentalMetadataApi = "io.rsocket.kotlin.ExperimentalMetadataApi"
const val ExperimentalStreamsApi = "io.rsocket.kotlin.ExperimentalStreamsApi"
const val RSocketLoggingApi = "io.rsocket.kotlin.RSocketLoggingApi"
}
Loading

0 comments on commit ec8442c

Please sign in to comment.