From 55b5e1b13767c12097943d64353baff2d3a49b6d Mon Sep 17 00:00:00 2001 From: olme04 <86063649+olme04@users.noreply.github.com> Date: Wed, 12 Jan 2022 13:06:32 +0300 Subject: [PATCH] Rework publication (#198) --- .github/workflows/gradle-main.yml | 28 --- .github/workflows/publish-branch.yml | 30 --- build.gradle.kts | 237 ------------------ buildSrc/build.gradle.kts | 8 + buildSrc/settings.gradle.kts | 20 ++ .../kotlin/rsocket.publication.gradle.kts | 85 +++++++ gradle/libs.versions.toml | 2 - rsocket-core/build.gradle.kts | 5 +- rsocket-transport-ktor/build.gradle.kts | 5 +- .../build.gradle.kts | 5 +- .../build.gradle.kts | 5 +- rsocket-transport-local/build.gradle.kts | 5 +- rsocket-transport-nodejs-tcp/build.gradle.kts | 5 +- 13 files changed, 119 insertions(+), 321 deletions(-) delete mode 100644 .github/workflows/publish-branch.yml create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/settings.gradle.kts create mode 100644 buildSrc/src/main/kotlin/rsocket.publication.gradle.kts diff --git a/.github/workflows/gradle-main.yml b/.github/workflows/gradle-main.yml index d1411d2d0..b669d2ec0 100644 --- a/.github/workflows/gradle-main.yml +++ b/.github/workflows/gradle-main.yml @@ -133,31 +133,3 @@ jobs: distributions-cache-enabled: false dependencies-cache-enabled: false configuration-cache-enabled: false - - publish: - needs: [ build, test ] - runs-on: macos-11 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: 8 - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/modules-2 - ~/.gradle/wrapper - ~/.konan - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - name: Set BRANCH_NAME for publication - run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - shell: bash - - name: Publish Packages to Artifactory (version x.y.z-SNAPSHOT) - uses: gradle/gradle-build-action@v1 - with: - arguments: artifactoryPublish -PbintrayUser=${{ secrets.bintrayUser }} -PbintrayKey=${{ secrets.bintrayKey }} -PversionSuffix=-SNAPSHOT -PbuildNumber=${{ github.run_number }} --info - distributions-cache-enabled: false - dependencies-cache-enabled: false - configuration-cache-enabled: false diff --git a/.github/workflows/publish-branch.yml b/.github/workflows/publish-branch.yml deleted file mode 100644 index 7d04d45d2..000000000 --- a/.github/workflows/publish-branch.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Publish Branch Snapshot -on: workflow_dispatch - -jobs: - publish: - runs-on: macos-11 - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 - with: - distribution: 'adopt' - java-version: 8 - - uses: actions/cache@v2 - with: - path: | - ~/.gradle/caches/modules-2 - ~/.gradle/wrapper - ~/.konan - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - name: Set BRANCH_NAME for publication - run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - shell: bash - - name: Publish Packages to Artifactory (version x.y.z-${{ env.BRANCH_NAME }}-SNAPSHOT) - uses: gradle/gradle-build-action@v1 - with: - arguments: artifactoryPublish -PbintrayUser=${{ secrets.bintrayUser }} -PbintrayKey=${{ secrets.bintrayKey }} -PversionSuffix=-${{ env.BRANCH_NAME }}-SNAPSHOT -PbuildNumber=${{ github.run_number }} --info - distributions-cache-enabled: false - dependencies-cache-enabled: false - configuration-cache-enabled: false diff --git a/build.gradle.kts b/build.gradle.kts index a92cc6336..91ae09aad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,6 @@ import groovy.util.* import org.gradle.api.publish.maven.internal.artifact.* import org.jetbrains.kotlin.gradle.dsl.* import org.jetbrains.kotlin.gradle.plugin.mpp.* -import org.jfrog.gradle.plugin.artifactory.dsl.* buildscript { repositories { @@ -33,14 +32,8 @@ buildscript { plugins { alias(libs.plugins.versionUpdates) - alias(libs.plugins.jfrog.artifactory) apply false //needed to add classpath to script } -//on macos it will return all publications supported by rsocket, as linux and mingw can be crosscompiled there for publication -//on linux and mac it will not contain mac targets -val Project.publicationNames: Array - get() = extensions.getByType().publications.names.toTypedArray() - subprojects { tasks.whenTaskAdded { if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") } @@ -194,233 +187,3 @@ subprojects { } } } - -fun publishPlatformArtifactsInRootModule( - platformPublication: MavenPublication, - kotlinMultiplatformPublication: MavenPublication -) { - lateinit var platformXml: XmlProvider - - platformPublication.pom.withXml { platformXml = this } - - kotlinMultiplatformPublication.apply { - pom.withXml { - val root = asNode() - // Remove the original content and add the content from the platform POM: - root.children().toList().forEach { root.remove(it as Node) } - platformXml.asNode().children() - .forEach { root.append(it as Node) } - - // Adjust the self artifact ID, as it should match the root module's coordinates: - ((root.get("artifactId") as NodeList)[0] as Node).setValue(artifactId) - - // Set packaging to POM to indicate that there's no artifact: - root.appendNode("packaging", "pom") - - // Remove the original platform dependencies and add a single dependency on the platform module: - val dependencies = (root.get("dependencies") as NodeList)[0] as Node - dependencies.children().toList() - .forEach { dependencies.remove(it as Node) } - val singleDependency = dependencies.appendNode("dependency") - singleDependency.appendNode( - "groupId", - platformPublication.groupId - ) - singleDependency.appendNode( - "artifactId", - platformPublication.artifactId - ) - singleDependency.appendNode( - "version", - platformPublication.version - ) - singleDependency.appendNode("scope", "compile") - } - } - - tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" } - .configureEach { - dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"]) - } - -} - -//publication -subprojects { - afterEvaluate { - - val versionSuffix: String? by project - if (versionSuffix != null) { - project.version = project.version.toString() + versionSuffix - } - - task("javadocJar") { - archiveClassifier.set("javadoc") - } - - tasks.withType { - dependsOn("javadocJar") - } - - plugins.withId("org.jetbrains.kotlin.multiplatform") { - extensions.configure { - targets.all { - mavenPublication { - pom { - name.set(project.name) - description.set(project.description) - 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") - } - } - } - } - } - } - - tasks.withType { - dependsOn(tasks.withType()) - } - - tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach { - tasks.findByName("generatePomFileForJvmPublication")?.let { dependsOn(it) } - } - } -} - -val bintrayUser: String? by project -val bintrayKey: String? by project -if (bintrayUser != null && bintrayKey != null) { - - //configure artifactory - subprojects { - plugins.withId("com.jfrog.artifactory") { - configure { - setContextUrl("https://oss.jfrog.org") - - publish(delegateClosureOf { - repository(delegateClosureOf { - setProperty("repoKey", "oss-snapshot-local") - setProperty("username", bintrayUser) - setProperty("password", bintrayKey) - setProperty("maven", true) - }) - println("Artifactory: ${publicationNames.contentToString()}") - defaults(delegateClosureOf { - invokeMethod("publications", publicationNames) - }) - }) - - val buildNumber: String? by project - - if (buildNumber != null) { - clientConfig.info.buildNumber = buildNumber - } - } - } - } -} - -//configure bintray / maven central -val sonatypeUsername: String? by project -val sonatypePassword: String? by project -if (sonatypeUsername != null && sonatypePassword != null) { - subprojects { - afterEvaluate { - plugins.withId("maven-publish") { - plugins.withId("signing") { - extensions.configure { - //requiring signature if there is a publish task that is not to MavenLocal -//TODO -// isRequired = gradle.taskGraph.allTasks.any { -// it.name.toLowerCase() -// .contains("publish") && !it.name.contains("MavenLocal") -// } - - val signingKey: String? by project - val signingPassword: String? by project - - useInMemoryPgpKeys(signingKey, signingPassword) - val names = publicationNames - val publishing: PublishingExtension by project.extensions - beforeEvaluate { - publishing.publications - .filterIsInstance() - .filter { it.name in names } - .forEach { publication -> - val moduleFile = - buildDir.resolve("publications/${publication.name}/module.json") - if (moduleFile.exists()) { - publication.artifact(object : - FileBasedMavenArtifact(moduleFile) { - override fun getDefaultExtension() = "module" - }) - } - } - } - afterEvaluate { - sign(*publishing.publications.toTypedArray()) - } - } - - extensions.configure { - repositories { - maven { - name = "sonatype" - url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2") - credentials { - username = sonatypeUsername - password = sonatypePassword - } - } - } - - publications.filterIsInstance().forEach { - // add empty javadocs - if (name != "kotlinMultiplatform") { - it.artifact(tasks["javadocJar"]) - } - - val type = it.name - when (type) { - "kotlinMultiplatform" -> { - // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with - // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too - it.artifactId = project.name - publishPlatformArtifactsInRootModule( - publications["jvm"] as MavenPublication, - it - ) - } - else -> it.artifactId = "${project.name}-$type" - } - } - } - } - } - } - } -} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 000000000..a9bae0750 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation(buildLibs.build.kotlin) + implementation(buildLibs.build.kotlinx.atomicfu) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 000000000..dc6733cb0 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,20 @@ +enableFeaturePreview("VERSION_CATALOGS") + +pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + } + + versionCatalogs { + create("buildLibs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/rsocket.publication.gradle.kts b/buildSrc/src/main/kotlin/rsocket.publication.gradle.kts new file mode 100644 index 000000000..f2dc16899 --- /dev/null +++ b/buildSrc/src/main/kotlin/rsocket.publication.gradle.kts @@ -0,0 +1,85 @@ +plugins { + `maven-publish` + signing +} + +val versionSuffix: String? by project +if (versionSuffix != null) { + project.version = project.version.toString() + versionSuffix +} + +//empty javadoc for maven central +val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } + +publishing { + publications.withType { + artifact(javadocJar.get()) + + pom { + name.set(project.name) + description.set(project.description) + 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") + } + } + } + + 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 + + repositories { + 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 && + signingKey != null && signingPassword != null + + useInMemoryPgpKeys(signingKey, signingPassword) + sign(publications) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d26ee577c..a99155396 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,6 @@ ktor = "1.6.7" turbine = "0.7.0" -jfrog-artifactory = "4.25.1" versionUpdates = "0.39.0" rsocket-java = "1.1.1" @@ -50,4 +49,3 @@ kotlin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "ko kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinx-benchmark" } versionUpdates = { id = "com.github.ben-manes.versions", version.ref = "versionUpdates" } -jfrog-artifactory = { id = "com.jfrog.artifactory", version.ref = "jfrog-artifactory" } diff --git a/rsocket-core/build.gradle.kts b/rsocket-core/build.gradle.kts index f9fd479c7..bec841320 100644 --- a/rsocket-core/build.gradle.kts +++ b/rsocket-core/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin { diff --git a/rsocket-transport-ktor/build.gradle.kts b/rsocket-transport-ktor/build.gradle.kts index 002961ceb..62abcd46a 100644 --- a/rsocket-transport-ktor/build.gradle.kts +++ b/rsocket-transport-ktor/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin { diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts b/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts index 1d8c5f0ae..6720297ab 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts +++ b/rsocket-transport-ktor/rsocket-transport-ktor-client/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin { diff --git a/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts b/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts index 53574273e..af7b08850 100644 --- a/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts +++ b/rsocket-transport-ktor/rsocket-transport-ktor-server/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin { diff --git a/rsocket-transport-local/build.gradle.kts b/rsocket-transport-local/build.gradle.kts index 93d822c48..c03f4e7a4 100644 --- a/rsocket-transport-local/build.gradle.kts +++ b/rsocket-transport-local/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin { diff --git a/rsocket-transport-nodejs-tcp/build.gradle.kts b/rsocket-transport-nodejs-tcp/build.gradle.kts index c5bd8af86..6653af90a 100644 --- a/rsocket-transport-nodejs-tcp/build.gradle.kts +++ b/rsocket-transport-nodejs-tcp/build.gradle.kts @@ -17,10 +17,7 @@ plugins { kotlin("multiplatform") id("kotlinx-atomicfu") - - signing - `maven-publish` - id("com.jfrog.artifactory") + rsocket.publication } kotlin {