Skip to content

Rework publication #198

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

Merged
merged 1 commit into from Jan 12, 2022
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
28 changes: 0 additions & 28 deletions .github/workflows/gradle-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 0 additions & 30 deletions .github/workflows/publish-branch.yml

This file was deleted.

237 changes: 0 additions & 237 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String>
get() = extensions.getByType<PublishingExtension>().publications.names.toTypedArray()

subprojects {
tasks.whenTaskAdded {
if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") }
Expand Down Expand Up @@ -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<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
}

tasks.withType<Sign> {
dependsOn("javadocJar")
}

plugins.withId("org.jetbrains.kotlin.multiplatform") {
extensions.configure<KotlinMultiplatformExtension> {
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<PublishToMavenRepository> {
dependsOn(tasks.withType<Sign>())
}

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<ArtifactoryPluginConvention> {
setContextUrl("https://oss.jfrog.org")

publish(delegateClosureOf<PublisherConfig> {
repository(delegateClosureOf<DoubleDelegateWrapper> {
setProperty("repoKey", "oss-snapshot-local")
setProperty("username", bintrayUser)
setProperty("password", bintrayKey)
setProperty("maven", true)
})
println("Artifactory: ${publicationNames.contentToString()}")
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
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<SigningExtension> {
//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<MavenPublication>()
.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<PublishingExtension> {
repositories {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
username = sonatypeUsername
password = sonatypePassword
}
}
}

publications.filterIsInstance<MavenPublication>().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"
}
}
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation(buildLibs.build.kotlin)
implementation(buildLibs.build.kotlinx.atomicfu)
}
20 changes: 20 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
enableFeaturePreview("VERSION_CATALOGS")

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
}

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