Browse Source

[libgdx][android] Fix release publishing to Central Portal

Mario Zechner 1 month ago
parent
commit
3aa7d29086

+ 19 - 1
spine-android/build.gradle.kts

@@ -14,6 +14,7 @@ plugins {
     alias(libs.plugins.androidApplication) apply false
     alias(libs.plugins.jetbrainsKotlinAndroid) apply false
     alias(libs.plugins.androidLibrary) apply false
+    id("org.jreleaser") version "1.17.0" apply false
 }
 
 // Read version from spine-libgdx gradle.properties to ensure consistency
@@ -31,7 +32,24 @@ fun getSpineVersion(): String {
     throw GradleException("version property not found in spine-libgdx gradle.properties")
 }
 
+// Placeholder functions - you need to implement these correctly!
+fun getRepositoryUsername(): String {
+    // Example: return project.findProperty("mavenCentralUsername") as? String ?: System.getenv("MAVEN_CENTRAL_USERNAME") ?: ""
+    return project.findProperty("sonatypeUsername") as? String ?: System.getenv("SONATYPE_USERNAME") ?: throw GradleException("Sonatype username not set")
+}
+
+fun getRepositoryPassword(): String {
+    // Example: return project.findProperty("mavenCentralPassword") as? String ?: System.getenv("MAVEN_CENTRAL_PASSWORD") ?: ""
+    return project.findProperty("sonatypePassword") as? String ?: System.getenv("SONATYPE_PASSWORD") ?: throw GradleException("Sonatype password not set")
+}
+
 allprojects {
     group = "com.esotericsoftware.spine"
     version = getSpineVersion()
-}
+}
+
+// Add a clean task for JReleaser
+tasks.register("clean") {
+    description = "Clean root project"
+}
+

+ 3 - 2
spine-android/publish.sh

@@ -26,8 +26,9 @@ VERSION=$(grep '^version=' ../spine-libgdx/gradle.properties | cut -d'=' -f2)
 
 if echo "$VERSION" | grep -q "SNAPSHOT"; then
     echo "Publishing SNAPSHOT version $VERSION to Central Portal..."
-    ./gradlew publishReleasePublicationToSonaTypeRepository --info
+    ./gradlew :spine-android:publishReleasePublicationToSonaTypeRepository --info
 else
     echo "Publishing RELEASE version $VERSION to Central Portal via JReleaser..."
-    ./gradlew publishRelease -PRELEASE --info
+    ./gradlew :spine-android:publishReleasePublicationToSonaTypeRepository -PRELEASE
+    ./gradlew :spine-android:jreleaserDeploy -PRELEASE --info
 fi

+ 23 - 10
spine-android/spine-android/build.gradle.kts

@@ -21,10 +21,6 @@ fun readSpineLibgdxProperty(propertyName: String): String {
     throw GradleException("Property '$propertyName' not found in spine-libgdx gradle.properties")
 }
 
-// JReleaser config for release builds to Central Portal
-if (project.hasProperty("RELEASE")) {
-    apply(plugin = "org.jreleaser")
-}
 
 android {
     namespace = "com.esotericsoftware.spine"
@@ -176,14 +172,31 @@ afterEvaluate {
     }
 }
 
-// For release builds, create a task that depends on publishing and finalizes with jreleaser
+// JReleaser config for release builds to Central Portal
 if (project.hasProperty("RELEASE")) {
-    tasks.register("publishRelease") {
-        dependsOn(tasks.withType<PublishToMavenRepository>())
-        doLast {
-            exec {
-                commandLine("./gradlew", "jreleaserDeploy")
+    apply(plugin = "org.jreleaser")
+
+    configure<org.jreleaser.gradle.plugin.JReleaserExtension> {
+        deploy {
+            maven {
+                mavenCentral {
+                    create("sonatype") {
+                        setActive("ALWAYS")
+                        url = "https://central.sonatype.com/api/v1/publisher"
+                        username = if (hasProperty("MAVEN_USERNAME")) property("MAVEN_USERNAME").toString() else ""
+                        password = if (hasProperty("MAVEN_PASSWORD")) property("MAVEN_PASSWORD").toString() else ""
+                        stagingRepository(layout.buildDirectory.dir("staging-deploy").get().asFile.absolutePath)
+                        sign = false
+                        verifyPom = false
+                    }
+                }
             }
         }
     }
+
+    tasks.register("publishRelease") {
+        dependsOn(tasks.withType<PublishToMavenRepository>())
+        finalizedBy(tasks.named("jreleaserDeploy"))
+    }
 }
+

+ 1 - 1
spine-libgdx/gradle.properties

@@ -1,5 +1,5 @@
 group=com.esotericsoftware.spine
-version=4.2.10-SNAPSHOT
+version=4.2.10
 libgdx_version=1.13.5
 POM_NAME=spine-libgdx
 POM_DESCRIPTION=Spine Runtime for libGDX

+ 2 - 1
spine-libgdx/publish.sh

@@ -29,5 +29,6 @@ if echo "$VERSION" | grep -q "SNAPSHOT"; then
     ./gradlew publishReleasePublicationToSonaTypeRepository
 else
     echo "Publishing RELEASE version $VERSION to Central Portal via JReleaser..."
-    ./gradlew publishRelease -PRELEASE
+    ./gradlew publishReleasePublicationToSonaTypeRepository -PRELEASE
+    ./gradlew jreleaserDeploy -PRELEASE
 fi

+ 24 - 3
spine-libgdx/publishing.gradle

@@ -92,8 +92,8 @@ project("spine-libgdx") {
                     name = "SonaType"
                     url = project.version.endsWith("-SNAPSHOT")
                             ? getSnapshotRepositoryUrl()
-                            // If release build, dump artifacts to local build/staging-deploy folder for consumption by jreleaser
-                            : layout.buildDirectory.dir('staging-deploy')
+                            // If release build, dump artifacts to root project build/staging-deploy folder for consumption by jreleaser
+                            : rootProject.layout.buildDirectory.dir('staging-deploy')
 
                     if (project.version.endsWith("-SNAPSHOT") && (getRepositoryUsername() || getRepositoryPassword())) {
                         credentials {
@@ -119,8 +119,29 @@ project("spine-libgdx") {
     }
 }
 
-// For release builds, create a task that depends on publishing and finalizes with jreleaser
+// JReleaser config for release builds to Central Portal
 if (project.hasProperty('RELEASE')) {
+    apply plugin: 'org.jreleaser'
+
+    jreleaser {
+        deploy {
+            maven {
+                mavenCentral {
+                    sonatype {
+                        active = 'ALWAYS'
+                        username = getRepositoryUsername()
+                        password = getRepositoryPassword()
+                        url = 'https://central.sonatype.com/api/v1/publisher'
+                        stagingRepository("${rootProject.buildDir}/staging-deploy")
+                        sign = false
+                        verifyPom = false
+                    }
+                }
+            }
+        }
+    }
+
+    // For release builds, create a task that depends on publishing and finalizes with jreleaser
     tasks.register('publishRelease') {
         dependsOn tasks.withType(PublishToMavenRepository)
         finalizedBy tasks.named('jreleaserDeploy')