Skip to content

Commit 5e6be50

Browse files
chippmannpiiertho
andauthored
Update jvm artifact deployment for new maven central portal (#838)
* Setup deployment plugin for the new maven plugin portal --------- Co-authored-by: Pierre-Thomas Meisels <meisels27@yahoo.fr>
1 parent 262c642 commit 5e6be50

File tree

10 files changed

+56
-128
lines changed

10 files changed

+56
-128
lines changed

.github/workflows/deploy_jvm.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ on:
1313
type: string
1414

1515
env:
16-
GODOT_KOTLIN_GPG_PRIVATE_KEY_ASCII: ${{ secrets.GODOT_KOTLIN_GPG_PRIVATE_KEY_ASCII }}
17-
GODOT_KOTLIN_GPG_KEY_PASSPHRASE: ${{ secrets.GODOT_KOTLIN_GPG_KEY_PASSPHRASE }}
18-
GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_USERNAME: ${{ secrets.GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_USERNAME }}
19-
GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_PASSWORD: ${{ secrets.GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_PASSWORD }}
16+
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.UTOPIA_RISE_GPG_PRIVATE_KEY_ASCII }}
17+
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.UTOPIA_RISE_GPG_KEY_PASSPHRASE }}
18+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.UTOPIA_RISE_MAVEN_CENTRAL_PORTAL_TOKEN_USERNAME }}
19+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.UTOPIA_RISE_MAVEN_CENTRAL_PORTAL_TOKEN_PASSWORD }}
2020
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
2121
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
2222
GODOT_KOTLIN_INTELLIJ_PLUGIN_PUBLISH: ${{secrets.GODOT_KOTLIN_INTELLIJ_PLUGIN_PUBLISH }}

kt/build-logic/convention/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ kotlin {
1212
dependencies {
1313
compileOnly(kotlin("gradle-plugin", version = libs.versions.kotlin.get()))
1414
implementation(libs.grgit)
15+
implementation(libs.maven.publish)
1516
}
1617

1718
gradlePlugin {
Lines changed: 39 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,45 @@
1+
12
package publish
23

4+
import com.vanniktech.maven.publish.MavenPublishBaseExtension
5+
import com.vanniktech.maven.publish.MavenPublishPlugin
6+
import com.vanniktech.maven.publish.SonatypeHost
37
import org.gradle.api.Plugin
48
import org.gradle.api.Project
5-
import org.gradle.api.plugins.JavaPluginExtension
69
import org.gradle.api.publish.PublishingExtension
710
import org.gradle.api.publish.maven.MavenPublication
8-
import org.gradle.api.tasks.SourceSetContainer
9-
import org.gradle.jvm.tasks.Jar
1011
import org.gradle.plugins.signing.Sign
11-
import org.gradle.plugins.signing.SigningExtension
1212

13+
@Suppress("unused") // false positive
1314
class PublishToMavenCentralPlugin : Plugin<Project> {
1415
override fun apply(target: Project) {
15-
target.plugins.apply("maven-publish")
16-
17-
val ossrhUser = target.propOrEnv("GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_USERNAME")
18-
val ossrhPassword = target.propOrEnv("GODOT_KOTLIN_MAVEN_CENTRAL_TOKEN_PASSWORD")
19-
val signingKey = target.propOrEnv("GODOT_KOTLIN_GPG_PRIVATE_KEY_ASCII")
20-
val signingPassword = target.propOrEnv("GODOT_KOTLIN_GPG_KEY_PASSPHRASE")
21-
val canSign = ossrhUser != null && ossrhPassword != null && signingKey != null && signingPassword != null
22-
23-
if (canSign) {
24-
target.plugins.apply("signing")
25-
target.logger.info("Will sign artifact for project \"${target.name}\" and setup publishing")
26-
} else {
27-
target.logger.warn("Cannot sign project \"${target.name}\" as credentials are missing. Will not setup signing and remote publishing credentials. Publishing will only work to maven local!")
28-
}
16+
target.plugins.apply(org.gradle.api.publish.maven.plugins.MavenPublishPlugin::class.java)
2917

30-
target.afterEvaluate { project ->
31-
val isReleaseMode = !(project.version as String).endsWith("-SNAPSHOT")
18+
target.afterEvaluate { evaluatedProject ->
19+
val mavenCentralUser = target.propOrEnv("ORG_GRADLE_PROJECT_mavenCentralUsername") ?: target.propOrEnv("mavenCentralUsername")
20+
val mavenCentralPassword = target.propOrEnv("ORG_GRADLE_PROJECT_mavenCentralPassword") ?: target.propOrEnv("mavenCentralPassword")
21+
val gpgInMemoryKey = target.propOrEnv("ORG_GRADLE_PROJECT_signingInMemoryKey") ?: target.propOrEnv("signingInMemoryKey")
22+
val gpgPassword = target.propOrEnv("ORG_GRADLE_PROJECT_signingInMemoryKeyPassword") ?: target.propOrEnv("signingInMemoryKeyPassword")
3223

33-
if (canSign) { // for local development, If missing in CI it will fail later on deploy so we would notice the issue then
34-
project.extensions.configure(SigningExtension::class.java) { signingExtension ->
35-
signingExtension.useInMemoryPgpKeys(signingKey, signingPassword)
36-
project.extensions.findByType(PublishingExtension::class.java)?.publications?.all { publication ->
37-
signingExtension.sign(publication)
38-
}
39-
}
40-
}
24+
val canSign = mavenCentralUser != null && mavenCentralPassword != null && gpgInMemoryKey != null && gpgPassword != null
4125

42-
project.extensions.getByType(JavaPluginExtension::class.java).apply {
43-
withSourcesJar()
44-
withJavadocJar()
45-
}
46-
47-
project.extensions.getByType(PublishingExtension::class.java).apply {
48-
repositories.apply {
49-
maven { mavenArtifactRepository ->
50-
val targetRepo = if (isReleaseMode) {
51-
"https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
52-
} else {
53-
"https://s01.oss.sonatype.org/content/repositories/snapshots/"
54-
}
55-
mavenArtifactRepository.setUrl(targetRepo)
56-
57-
if (canSign) {
58-
mavenArtifactRepository.credentials { passwordCredentials ->
59-
passwordCredentials.username = ossrhUser
60-
passwordCredentials.password = ossrhPassword
61-
}
62-
}
63-
}
64-
}
26+
target.extensions.getByType(PublishingExtension::class.java).apply {
6527
publications { publicationContainer ->
6628
publicationContainer.all { publication ->
6729
if (publication is MavenPublication) {
6830
publication.groupId = "com.utopia-rise"
6931
val artifactId = publication.artifactId
70-
publication.artifactId = if (artifactId.isNullOrEmpty()) project.name else artifactId
71-
publication.version = project.version as String
32+
publication.artifactId = if (artifactId.isNullOrEmpty()) target.name else artifactId
33+
publication.version = target.version as String
7234

7335
publication.pom { mavenPom ->
7436
mavenPom.url.set("https://github.com/utopia-rise/godot-kotlin-jvm.git")
7537

7638
if (mavenPom.name.getOrElse("").isNullOrEmpty()) {
77-
mavenPom.name.set(project.name)
39+
mavenPom.name.set(target.name)
7840
}
7941
if (mavenPom.description.getOrElse("").isNullOrEmpty()) {
80-
mavenPom.description.set(project.description ?: "Godot kotlin jvm module")
42+
mavenPom.description.set(target.description ?: "Godot kotlin jvm module")
8143
}
8244

8345
mavenPom.scm { mavenPomScm ->
@@ -127,22 +89,33 @@ class PublishToMavenCentralPlugin : Plugin<Project> {
12789
}
12890
}
12991

92+
13093
if (canSign) {
131-
project
132-
.tasks
133-
.filter { task -> task.name.startsWith("publish") }
134-
.forEach { task ->
135-
task.dependsOn(project.tasks.withType(Sign::class.java))
136-
}
94+
evaluatedProject.logger.info("Will sign artifact for project \"${evaluatedProject.name}\" and setup publishing")
95+
96+
evaluatedProject.pluginManager.apply(MavenPublishPlugin::class.java)
97+
evaluatedProject.extensions.getByType(MavenPublishBaseExtension::class.java).apply {
98+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
99+
signAllPublications()
100+
}
101+
102+
target.afterEvaluate {
103+
target
104+
.tasks
105+
.filter { task -> task.name.startsWith("publish") }
106+
.forEach { task ->
107+
task.dependsOn(target.tasks.withType(Sign::class.java))
108+
}
109+
}
110+
} else {
111+
evaluatedProject.logger.warn("Cannot sign project \"${evaluatedProject.name}\" as credentials are missing. Will not setup signing and remote publishing credentials. Publishing will only work to maven local!")
137112
}
138113
}
139114
}
140115
}
141116

142117
fun Project.propOrEnv(name: String): String? {
143-
var property: String? = findProperty(name) as String?
144-
if (property == null) {
145-
property = System.getenv(name)
146-
}
147-
return property
118+
return findProperty(name) as? String?
119+
?: System.getenv(name)?.ifEmpty { null }
120+
?: providers.systemProperty(name).orNull
148121
}

kt/godot-library/build.gradle.kts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
21
import versioninfo.fullGodotKotlinJvmVersion
32

43
plugins {
@@ -31,11 +30,6 @@ kotlin {
3130
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
3231
}
3332

34-
java {
35-
withSourcesJar()
36-
withJavadocJar()
37-
}
38-
3933
dependencies {
4034
// added here as a transitive dependency so the user can use reflection
4135
// we need to add it here so reflection is available where the code is loaded (Bootstrap.kt) otherwise it will not work
@@ -62,17 +56,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
6256

6357
publishing {
6458
publications {
65-
@Suppress("UNUSED_VARIABLE")
59+
@Suppress("UNUSED_VARIABLE", "unused")
6660
val godotLibraryPublication by registering(MavenPublication::class) {
6761
pom {
6862
name.set("${project.name}-$targetSuffix")
6963
description.set("A library allowing to define scripts for the Godot Engine.")
7064
}
7165
artifactId = "godot-library-$targetSuffix"
7266
description = "A library allowing to define scripts for the Godot Engine."
73-
artifact(tasks.jar)
74-
artifact(tasks.getByName("sourcesJar"))
75-
artifact(tasks.getByName("javadocJar"))
7667
}
7768
}
7869
}

kt/godot-library/godot-api-library/build.gradle.kts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ kotlin {
1818
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
1919
}
2020

21-
java {
22-
withSourcesJar()
23-
withJavadocJar()
24-
}
25-
2621
dependencies {
2722
api("com.utopia-rise:common:$fullGodotKotlinJvmVersion")
2823
implementation(project(":godot-internal-library"))
@@ -44,17 +39,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
4439

4540
publishing {
4641
publications {
47-
@Suppress("UNUSED_VARIABLE")
48-
val godotLibraryPublication by registering(MavenPublication::class) {
42+
@Suppress("UNUSED_VARIABLE", "unused")
43+
val godotApiLibraryPublication by registering(MavenPublication::class) {
4944
pom {
5045
name.set("${project.name}-$targetSuffix")
5146
description.set("Contains godot api as kotlin classes and jvm cpp interaction code.")
5247
}
5348
artifactId = "godot-api-library-$targetSuffix"
5449
description = "Contains godot generated api as kotlin classes and jvm cpp interaction code."
55-
artifact(tasks.jar)
56-
artifact(tasks.getByName("sourcesJar"))
57-
artifact(tasks.getByName("javadocJar"))
5850
}
5951
}
6052
}

kt/godot-library/godot-core-library/build.gradle.kts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ kotlin {
1818
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
1919
}
2020

21-
java {
22-
withSourcesJar()
23-
withJavadocJar()
24-
}
25-
2621
dependencies {
2722
api("com.utopia-rise:common:$fullGodotKotlinJvmVersion")
2823
implementation(project(":godot-internal-library"))
@@ -47,17 +42,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
4742

4843
publishing {
4944
publications {
50-
@Suppress("UNUSED_VARIABLE")
51-
val godotLibraryPublication by creating(MavenPublication::class) {
45+
@Suppress("UNUSED_VARIABLE", "unused")
46+
val godotCoreLibraryPublication by creating(MavenPublication::class) {
5247
pom {
5348
name.set("${project.name}-$targetSuffix")
5449
description.set("Contains godot api as kotlin classes and jvm cpp interaction code.")
5550
}
5651
artifactId = "godot-core-library-$targetSuffix"
5752
description = "Contains godot api as kotlin classes and jvm cpp interaction code."
58-
artifact(tasks.jar)
59-
artifact(tasks.getByName("sourcesJar"))
60-
artifact(tasks.getByName("javadocJar"))
6153
}
6254
}
6355
}

kt/godot-library/godot-coroutine-library/build.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ kotlin {
1818
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
1919
}
2020

21-
java {
22-
withSourcesJar()
23-
withJavadocJar()
24-
}
25-
2621
dependencies {
2722
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${libs.versions.kotlinCoroutine.get()}")
2823
api("com.utopia-rise:common:$fullGodotKotlinJvmVersion")
@@ -48,17 +43,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
4843

4944
publishing {
5045
publications {
51-
@Suppress("UNUSED_VARIABLE")
46+
@Suppress("UNUSED_VARIABLE", "unused")
5247
val godotCoroutineLibraryPublication by creating(MavenPublication::class) {
5348
pom {
5449
name.set("${project.name}-$targetSuffix")
5550
description.set("Godot library extension allowing the use of coroutines in a Godot context.")
5651
}
5752
artifactId = "godot-coroutine-library-$targetSuffix"
5853
description = "Godot library extension allowing the use of coroutines in a Godot context."
59-
artifact(tasks.jar)
60-
artifact(tasks.getByName("sourcesJar"))
61-
artifact(tasks.getByName("javadocJar"))
6254
}
6355
}
6456
}

kt/godot-library/godot-extension-library/build.gradle.kts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ kotlin {
1919
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
2020
}
2121

22-
java {
23-
withSourcesJar()
24-
withJavadocJar()
25-
}
26-
2722
dependencies {
2823
api("com.utopia-rise:common:$fullGodotKotlinJvmVersion")
2924
implementation(project(":godot-internal-library"))
@@ -46,17 +41,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
4641

4742
publishing {
4843
publications {
49-
@Suppress("UNUSED_VARIABLE")
50-
val godotCoroutineLibraryPublication by creating(MavenPublication::class) {
44+
@Suppress("UNUSED_VARIABLE", "unused")
45+
val godotExtensionLibraryPublication by creating(MavenPublication::class) {
5146
pom {
5247
name.set("${project.name}-$targetSuffix")
5348
description.set("Godot library extension build on top of the base Godot API.")
5449
}
5550
artifactId = "godot-extension-library-$targetSuffix"
5651
description = "Godot library extension build on top of the base Godot API."
57-
artifact(tasks.jar)
58-
artifact(tasks.getByName("sourcesJar"))
59-
artifact(tasks.getByName("javadocJar"))
6052
}
6153
}
6254
}

kt/godot-library/godot-internal-library/build.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ kotlin {
1818
jvmToolchain(libs.versions.toolchain.jvm.get().toInt())
1919
}
2020

21-
java {
22-
withSourcesJar()
23-
withJavadocJar()
24-
}
25-
2621
dependencies {
2722
// added here as a transitive dependency so the user can use reflection
2823
// we need to add it here so reflection is available where the code is loaded (Bootstrap.kt) otherwise it will not work
@@ -33,17 +28,14 @@ val targetSuffix = if (isRelease) "release" else "debug"
3328

3429
publishing {
3530
publications {
36-
@Suppress("UNUSED_VARIABLE")
31+
@Suppress("UNUSED_VARIABLE", "unused")
3732
val godotInternalLibraryPublication by creating(MavenPublication::class) {
3833
pom {
3934
name.set("${project.name}-$targetSuffix")
4035
description.set("Contains internal utilities for the Godot kotlin libraries")
4136
}
4237
artifactId = "godot-internal-library-$targetSuffix"
4338
description = "Contains internal utilities for the Godot kotlin libraries"
44-
artifact(tasks.jar)
45-
artifact(tasks.getByName("sourcesJar"))
46-
artifact(tasks.getByName("javadocJar"))
4739
}
4840
}
4941
}

kt/gradle/libs.versions.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jacksonDataFormatXml = "2.18.2" # https://mvnrepository.com/artifact/com.fasterx
2121
grgit = "5.3.0" # https://github.com/ajoberstar/grgit/releases
2222

2323
gradlePublish = "1.3.1" # https://plugins.gradle.org/plugin/com.gradle.plugin-publish
24+
maven-publish="0.32.0" # https://github.com/vanniktech/gradle-maven-publish-plugin/releases
2425

2526
changelog = "2.2.1" # https://github.com/JetBrains/gradle-changelog-plugin/releases
2627
gradleIntelliJPlugin = "2.3.0" # https://github.com/JetBrains/intellij-platform-gradle-plugin/releases
@@ -41,6 +42,8 @@ jacksonDataFormatXml = { module = "com.fasterxml.jackson.dataformat:jackson-data
4142
grgit = { module = "org.ajoberstar.grgit:grgit-gradle", version.ref = "grgit" }
4243
ideaSync = { module = "org.jetbrains.gradle.plugin.idea-ext:org.jetbrains.gradle.plugin.idea-ext.gradle.plugin", version.ref = "ideaSync" }
4344

45+
maven-publish = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "maven-publish" } # needed for publishing to new maven central repositories
46+
4447
[plugins]
4548
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
4649
gradleIntelliJPlugin = { id = "org.jetbrains.intellij.platform", version.ref = "gradleIntelliJPlugin" }

0 commit comments

Comments
 (0)