Skip to content

Commit bcd8d95

Browse files
chore: switch out the default maven publisher for one that actually works with Sonatype
1 parent 59273dc commit bcd8d95

13 files changed

+236
-413
lines changed

.github/workflows/gradle-publish-github.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222

2323
steps:
2424
- uses: actions/checkout@v4
25-
- name: Set up JDK 23
25+
- name: Set up JDK 24
2626
uses: actions/setup-java@v4
2727
with:
28-
java-version: '23'
28+
java-version: '24'
2929
distribution: 'temurin'
3030
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
3131
settings-path: ${{ github.workspace }} # location for the settings.xml file
@@ -39,11 +39,11 @@ jobs:
3939
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
4040
# the publishing section of your build.gradle
4141
- name: Publish to GitHub Packages
42-
run: ./gradlew publish -Prepo=GitHubPackages
42+
run: ./gradlew publishAllPublicationsToGitHubPackagesRepository
4343
env:
4444
GITHUB_ACTOR: ${{ github.actor }}
4545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
SIGNING_KEY_ID: ${{ vars.SIGNING_KEY_ID }}
47-
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
48-
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
46+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ vars.SIGNING_KEY_ID }}
47+
ORG_GRADLE_PROJECT_singingInMemoryKey: ${{ secrets.SIGNING_KEY }}
48+
ORG_GRADLE_PROJECT_singingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
4949

.github/workflows/gradle-publish-maven.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222

2323
steps:
2424
- uses: actions/checkout@v4
25-
- name: Set up JDK 23
25+
- name: Set up JDK 24
2626
uses: actions/setup-java@v4
2727
with:
28-
java-version: '23'
28+
java-version: '24'
2929
distribution: 'temurin'
3030
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
3131
settings-path: ${{ github.workspace }} # location for the settings.xml file
@@ -39,13 +39,12 @@ jobs:
3939
# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
4040
# the publishing section of your build.gradle
4141
- name: Publish to Sonatype (Maven)
42-
run: ./gradlew publish -Prepo=Sonatype
42+
run: ./gradlew publishAllPublicationsToMavenCentralRepository
4343
env:
4444
GITHUB_ACTOR: ${{ github.actor }}
4545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
SONATYPE_USER: ${{ vars.SONATYPE_USER }}
47-
SONATYPE_TOKEN: ${{ secrets.SONATYPE_TOKEN }}
48-
SIGNING_KEY_ID: ${{ vars.SIGNING_KEY_ID }}
49-
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
50-
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
51-
46+
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ vars.SONATYPE_USER }}
47+
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_TOKEN }}
48+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ vars.SIGNING_KEY_ID }}
49+
ORG_GRADLE_PROJECT_singingInMemoryKey: ${{ secrets.SIGNING_KEY }}
50+
ORG_GRADLE_PROJECT_singingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}

.github/workflows/gradle.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: actions/setup-java@v4
2727
with:
2828
# https://github.com/actions/setup-java?tab=readme-ov-file#supported-distributions
29-
java-version: '23'
29+
java-version: '24'
3030
distribution: 'temurin'
3131

3232
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
@@ -60,7 +60,7 @@ jobs:
6060
uses: actions/setup-java@v4
6161
with:
6262
# https://github.com/actions/setup-java?tab=readme-ov-file#supported-distributions
63-
java-version: '23'
63+
java-version: '24'
6464
distribution: 'temurin'
6565

6666
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
@@ -69,6 +69,6 @@ jobs:
6969
uses: gradle/actions/dependency-submission@dbbdc275be76ac10734476cc723d82dfe7ec6eda # v3.4.2
7070

7171
env:
72-
SIGNING_KEY_ID: ${{ vars.SIGNING_KEY_ID }}
73-
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
74-
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
72+
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ vars.SIGNING_KEY_ID }}
73+
ORG_GRADLE_PROJECT_singingInMemoryKey: ${{ secrets.SIGNING_KEY }}
74+
ORG_GRADLE_PROJECT_singingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}

api/build.gradle.kts

Lines changed: 32 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import java.io.File
21
import java.util.*
2+
import com.vanniktech.maven.publish.SonatypeHost
33

44
plugins {
55
id("buildlogic.java-library-conventions")
6-
signing
6+
// Apply the maven-publish plugin from com.vanniktech for publishing to repositories
7+
id("com.vanniktech.maven.publish")
78
}
89

10+
group = "org.xxdc.oss.example"
11+
912
val libPath = "native/src/main/rust/target/debug"
1013
val osName = System.getProperty("os.name").lowercase()
1114
val osArch = System.getProperty("os.arch").lowercase()
@@ -40,13 +43,6 @@ tasks.register<JavaExec>("jmh") {
4043
args = listOf("org.xxdc.oss.example.interop.benchmark.PlayerIdsBenchmark")
4144
}
4245

43-
java {
44-
withJavadocJar()
45-
withSourcesJar()
46-
}
47-
48-
49-
5046
// TODO: Disable preview features on the branch when the next JDK is released
5147
val enablePreviewFeatures = true
5248

@@ -81,97 +77,36 @@ if (enablePreviewFeatures) {
8177
}
8278
}
8379
}
84-
// https://docs.gradle.org/current/userguide/publishing_maven.html
80+
81+
// Publishing
82+
mavenPublishing {
83+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
84+
val signingKey = (findProperty("signingInMemoryKey") ?: findProperty("signing.key")) as String?
85+
//if (signingKey != null) {
86+
if (false) {
87+
signAllPublications()
88+
}
89+
90+
coordinates (
91+
project.group as String?,
92+
"tictactoe-api",
93+
project.version as String?
94+
)
95+
pom {
96+
name.set("tictactoe-api")
97+
description.set("An Over-Engineered Tic Tac Toe Game API")
98+
}
99+
}
100+
85101
publishing {
86102
repositories {
87-
// Publish to GitHub Packages
88-
// https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-java-packages-with-gradle
89-
val targetRepo: String? = findProperty("repo") as String?
90-
if (targetRepo == null || targetRepo == "Sonatype") {
91-
maven {
92-
name = "Sonatype"
93-
url = uri(
94-
if (version.toString().endsWith("SNAPSHOT"))
95-
//"https://s01.oss.sonatype.org/content/repositories/snapshots/"
96-
"https://central.sonatype.com/repository/maven-snapshots/"
97-
else
98-
// "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
99-
"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2"
100-
)
101-
credentials {
102-
username = project.findProperty("sonatype.user") as String? ?: System.getenv("SONATYPE_USER")
103-
password = project.findProperty("sonatype.key") as String? ?: System.getenv("SONATYPE_TOKEN")
104-
}
105-
}
106-
}
107-
if (targetRepo == null || targetRepo == "GitHubPackages") {
108-
maven {
109-
name = "GitHubPackages"
110-
url = uri("https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe")
111-
credentials {
112-
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
113-
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
114-
}
115-
}
116-
}
117-
}
118-
publications {
119-
create<MavenPublication>("maven") {
120-
groupId = "org.xxdc.oss.example"
121-
artifactId = "tictactoe-api"
122-
from(components["java"])
123-
pom {
124-
name.set("tictactoe")
125-
description.set("An Over-Engineered Tic Tac Toe Game API")
126-
url.set("https://github.com/briancorbinxyz/overengineering-tictactoe")
127-
licenses {
128-
license {
129-
name.set("MIT License")
130-
url.set("https://opensource.org/licenses/MIT")
131-
}
132-
developers {
133-
developer {
134-
id.set("briancorbinxyz")
135-
name.set("Brian Corbin")
136-
email.set("mail@briancorbin.xyz")
137-
}
138-
}
139-
}
140-
scm {
141-
connection.set("scm:git:git://github.com/briancorbinxyz/overengineering-tictactoe.git")
142-
developerConnection.set("scm:git:ssh://github.com/briancorbinxyz/overengineering-tictactoe.git")
143-
url.set("https://github.com/briancorbinxyz/overengineering-tictactoe")
144-
}
103+
maven {
104+
name = "GitHubPackages"
105+
url = uri("https://maven.pkg.github.com/briancorbinxyz/overengineering-tictactoe")
106+
credentials {
107+
username = findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
108+
password = findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
145109
}
146110
}
147111
}
148112
}
149-
fun decodeKey(raw: String): String =
150-
if (raw.contains("-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
151-
raw
152-
} else {
153-
String(Base64.getDecoder().decode(raw))
154-
}
155-
156-
val rawSigningKey = System.getenv("SIGNING_KEY") ?: findProperty("signing.key") as String?
157-
val signingKey = rawSigningKey?.let(::decodeKey)
158-
159-
val signingPassword = System.getenv("SIGNING_PASSWORD") ?: findProperty("signing.password") as String?
160-
val signingKeyId = System.getenv("SIGNING_KEY_ID") ?: findProperty("signing.keyId") as String?
161-
162-
val isPublishing = gradle.startParameter.taskNames.any { it.contains("publish", ignoreCase = true) }
163-
164-
val shouldSign = signingKey != null && signingPassword != null
165-
166-
logger.lifecycle("🔐 Signing check:")
167-
logger.lifecycle(" • isPublishing: $isPublishing")
168-
logger.lifecycle(" • signingKeyId: ${signingKeyId != null}")
169-
logger.lifecycle(" • signingKey present: ${signingKey != null}")
170-
logger.lifecycle(" • signingPassword present: ${signingPassword != null}")
171-
logger.lifecycle(" • shouldSign: $shouldSign")
172-
if (isPublishing && shouldSign) {
173-
signing {
174-
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
175-
sign(configurations.runtimeElements.get())
176-
}
177-
}

0 commit comments

Comments
 (0)