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

Cleanup build logic #252

Merged
merged 2 commits into from
May 13, 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
2 changes: 1 addition & 1 deletion .github/actions/setup-gradle/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ runs:
8
11
17
20
21
- name: Setup gradle
uses: gradle/gradle-build-action@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
jvmTest
jvm11Test
jvm17Test
jvm20Test
jvm21Test
--scan
--info
--continue
Expand Down 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("[email protected]")
}
developer {
id.set("OlegDokuka")
name.set("Oleh Dokuka")
email.set("[email protected]")
}
}
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
Loading