Skip to content

Commit 55b5e1b

Browse files
author
olme04
authored
Rework publication (#198)
1 parent af8a5b8 commit 55b5e1b

File tree

13 files changed

+119
-321
lines changed

13 files changed

+119
-321
lines changed

.github/workflows/gradle-main.yml

-28
Original file line numberDiff line numberDiff line change
@@ -133,31 +133,3 @@ jobs:
133133
distributions-cache-enabled: false
134134
dependencies-cache-enabled: false
135135
configuration-cache-enabled: false
136-
137-
publish:
138-
needs: [ build, test ]
139-
runs-on: macos-11
140-
steps:
141-
- uses: actions/checkout@v2
142-
- uses: actions/setup-java@v2
143-
with:
144-
distribution: 'adopt'
145-
java-version: 8
146-
- uses: actions/cache@v2
147-
with:
148-
path: |
149-
~/.gradle/caches/modules-2
150-
~/.gradle/wrapper
151-
~/.konan
152-
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }}
153-
restore-keys: ${{ runner.os }}-gradle-
154-
- name: Set BRANCH_NAME for publication
155-
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
156-
shell: bash
157-
- name: Publish Packages to Artifactory (version x.y.z-SNAPSHOT)
158-
uses: gradle/gradle-build-action@v1
159-
with:
160-
arguments: artifactoryPublish -PbintrayUser=${{ secrets.bintrayUser }} -PbintrayKey=${{ secrets.bintrayKey }} -PversionSuffix=-SNAPSHOT -PbuildNumber=${{ github.run_number }} --info
161-
distributions-cache-enabled: false
162-
dependencies-cache-enabled: false
163-
configuration-cache-enabled: false

.github/workflows/publish-branch.yml

-30
This file was deleted.

build.gradle.kts

-237
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import groovy.util.*
1818
import org.gradle.api.publish.maven.internal.artifact.*
1919
import org.jetbrains.kotlin.gradle.dsl.*
2020
import org.jetbrains.kotlin.gradle.plugin.mpp.*
21-
import org.jfrog.gradle.plugin.artifactory.dsl.*
2221

2322
buildscript {
2423
repositories {
@@ -33,14 +32,8 @@ buildscript {
3332

3433
plugins {
3534
alias(libs.plugins.versionUpdates)
36-
alias(libs.plugins.jfrog.artifactory) apply false //needed to add classpath to script
3735
}
3836

39-
//on macos it will return all publications supported by rsocket, as linux and mingw can be crosscompiled there for publication
40-
//on linux and mac it will not contain mac targets
41-
val Project.publicationNames: Array<String>
42-
get() = extensions.getByType<PublishingExtension>().publications.names.toTypedArray()
43-
4437
subprojects {
4538
tasks.whenTaskAdded {
4639
if (name.endsWith("test", ignoreCase = true)) onlyIf { !rootProject.hasProperty("skipTests") }
@@ -194,233 +187,3 @@ subprojects {
194187
}
195188
}
196189
}
197-
198-
fun publishPlatformArtifactsInRootModule(
199-
platformPublication: MavenPublication,
200-
kotlinMultiplatformPublication: MavenPublication
201-
) {
202-
lateinit var platformXml: XmlProvider
203-
204-
platformPublication.pom.withXml { platformXml = this }
205-
206-
kotlinMultiplatformPublication.apply {
207-
pom.withXml {
208-
val root = asNode()
209-
// Remove the original content and add the content from the platform POM:
210-
root.children().toList().forEach { root.remove(it as Node) }
211-
platformXml.asNode().children()
212-
.forEach { root.append(it as Node) }
213-
214-
// Adjust the self artifact ID, as it should match the root module's coordinates:
215-
((root.get("artifactId") as NodeList)[0] as Node).setValue(artifactId)
216-
217-
// Set packaging to POM to indicate that there's no artifact:
218-
root.appendNode("packaging", "pom")
219-
220-
// Remove the original platform dependencies and add a single dependency on the platform module:
221-
val dependencies = (root.get("dependencies") as NodeList)[0] as Node
222-
dependencies.children().toList()
223-
.forEach { dependencies.remove(it as Node) }
224-
val singleDependency = dependencies.appendNode("dependency")
225-
singleDependency.appendNode(
226-
"groupId",
227-
platformPublication.groupId
228-
)
229-
singleDependency.appendNode(
230-
"artifactId",
231-
platformPublication.artifactId
232-
)
233-
singleDependency.appendNode(
234-
"version",
235-
platformPublication.version
236-
)
237-
singleDependency.appendNode("scope", "compile")
238-
}
239-
}
240-
241-
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }
242-
.configureEach {
243-
dependsOn(tasks["generatePomFileFor${platformPublication.name.capitalize()}Publication"])
244-
}
245-
246-
}
247-
248-
//publication
249-
subprojects {
250-
afterEvaluate {
251-
252-
val versionSuffix: String? by project
253-
if (versionSuffix != null) {
254-
project.version = project.version.toString() + versionSuffix
255-
}
256-
257-
task<Jar>("javadocJar") {
258-
archiveClassifier.set("javadoc")
259-
}
260-
261-
tasks.withType<Sign> {
262-
dependsOn("javadocJar")
263-
}
264-
265-
plugins.withId("org.jetbrains.kotlin.multiplatform") {
266-
extensions.configure<KotlinMultiplatformExtension> {
267-
targets.all {
268-
mavenPublication {
269-
pom {
270-
name.set(project.name)
271-
description.set(project.description)
272-
url.set("http://rsocket.io")
273-
274-
licenses {
275-
license {
276-
name.set("The Apache Software License, Version 2.0")
277-
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
278-
distribution.set("repo")
279-
}
280-
}
281-
developers {
282-
developer {
283-
id.set("whyoleg")
284-
name.set("Oleg Yukhnevich")
285-
email.set("[email protected]")
286-
}
287-
developer {
288-
id.set("OlegDokuka")
289-
name.set("Oleh Dokuka")
290-
email.set("[email protected]")
291-
}
292-
}
293-
scm {
294-
connection.set("https://github.com/rsocket/rsocket-kotlin.git")
295-
developerConnection.set("https://github.com/rsocket/rsocket-kotlin.git")
296-
url.set("https://github.com/rsocket/rsocket-kotlin")
297-
}
298-
}
299-
}
300-
}
301-
}
302-
}
303-
304-
tasks.withType<PublishToMavenRepository> {
305-
dependsOn(tasks.withType<Sign>())
306-
}
307-
308-
tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication" }.configureEach {
309-
tasks.findByName("generatePomFileForJvmPublication")?.let { dependsOn(it) }
310-
}
311-
}
312-
}
313-
314-
val bintrayUser: String? by project
315-
val bintrayKey: String? by project
316-
if (bintrayUser != null && bintrayKey != null) {
317-
318-
//configure artifactory
319-
subprojects {
320-
plugins.withId("com.jfrog.artifactory") {
321-
configure<ArtifactoryPluginConvention> {
322-
setContextUrl("https://oss.jfrog.org")
323-
324-
publish(delegateClosureOf<PublisherConfig> {
325-
repository(delegateClosureOf<DoubleDelegateWrapper> {
326-
setProperty("repoKey", "oss-snapshot-local")
327-
setProperty("username", bintrayUser)
328-
setProperty("password", bintrayKey)
329-
setProperty("maven", true)
330-
})
331-
println("Artifactory: ${publicationNames.contentToString()}")
332-
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
333-
invokeMethod("publications", publicationNames)
334-
})
335-
})
336-
337-
val buildNumber: String? by project
338-
339-
if (buildNumber != null) {
340-
clientConfig.info.buildNumber = buildNumber
341-
}
342-
}
343-
}
344-
}
345-
}
346-
347-
//configure bintray / maven central
348-
val sonatypeUsername: String? by project
349-
val sonatypePassword: String? by project
350-
if (sonatypeUsername != null && sonatypePassword != null) {
351-
subprojects {
352-
afterEvaluate {
353-
plugins.withId("maven-publish") {
354-
plugins.withId("signing") {
355-
extensions.configure<SigningExtension> {
356-
//requiring signature if there is a publish task that is not to MavenLocal
357-
//TODO
358-
// isRequired = gradle.taskGraph.allTasks.any {
359-
// it.name.toLowerCase()
360-
// .contains("publish") && !it.name.contains("MavenLocal")
361-
// }
362-
363-
val signingKey: String? by project
364-
val signingPassword: String? by project
365-
366-
useInMemoryPgpKeys(signingKey, signingPassword)
367-
val names = publicationNames
368-
val publishing: PublishingExtension by project.extensions
369-
beforeEvaluate {
370-
publishing.publications
371-
.filterIsInstance<MavenPublication>()
372-
.filter { it.name in names }
373-
.forEach { publication ->
374-
val moduleFile =
375-
buildDir.resolve("publications/${publication.name}/module.json")
376-
if (moduleFile.exists()) {
377-
publication.artifact(object :
378-
FileBasedMavenArtifact(moduleFile) {
379-
override fun getDefaultExtension() = "module"
380-
})
381-
}
382-
}
383-
}
384-
afterEvaluate {
385-
sign(*publishing.publications.toTypedArray())
386-
}
387-
}
388-
389-
extensions.configure<PublishingExtension> {
390-
repositories {
391-
maven {
392-
name = "sonatype"
393-
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2")
394-
credentials {
395-
username = sonatypeUsername
396-
password = sonatypePassword
397-
}
398-
}
399-
}
400-
401-
publications.filterIsInstance<MavenPublication>().forEach {
402-
// add empty javadocs
403-
if (name != "kotlinMultiplatform") {
404-
it.artifact(tasks["javadocJar"])
405-
}
406-
407-
val type = it.name
408-
when (type) {
409-
"kotlinMultiplatform" -> {
410-
// With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with
411-
// the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too
412-
it.artifactId = project.name
413-
publishPlatformArtifactsInRootModule(
414-
publications["jvm"] as MavenPublication,
415-
it
416-
)
417-
}
418-
else -> it.artifactId = "${project.name}-$type"
419-
}
420-
}
421-
}
422-
}
423-
}
424-
}
425-
}
426-
}

buildSrc/build.gradle.kts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
dependencies {
6+
implementation(buildLibs.build.kotlin)
7+
implementation(buildLibs.build.kotlinx.atomicfu)
8+
}

buildSrc/settings.gradle.kts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
enableFeaturePreview("VERSION_CATALOGS")
2+
3+
pluginManagement {
4+
repositories {
5+
gradlePluginPortal()
6+
mavenCentral()
7+
}
8+
}
9+
10+
dependencyResolutionManagement {
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
versionCatalogs {
16+
create("buildLibs") {
17+
from(files("../gradle/libs.versions.toml"))
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)