Skip to content

Commit 3353279

Browse files
Update Sonatype publishing to use OSSRH Staging Repository
1 parent a8c83d9 commit 3353279

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

.github/workflows/publish.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Publish to Maven Central
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
15+
- name: Set up JDK
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: 11
19+
distribution: 'temurin'
20+
21+
- name: Publish to Maven Central
22+
run: ./gradlew publish
23+
env:
24+
ORG_GRADLE_PROJECT_NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }}
25+
ORG_GRADLE_PROJECT_NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
26+
ORG_GRADLE_PROJECT_SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
27+
ORG_GRADLE_PROJECT_SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
28+
ORG_GRADLE_PROJECT_SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
29+
30+
- name: Check version
31+
id: version
32+
run: |
33+
version=$(grep "detektExtensionVersion" gradle.properties | cut -d'=' -f2 | tr -d ' ')
34+
if [[ "$version" != *"SNAPSHOT"* ]]; then
35+
echo "is_release=true" >> $GITHUB_OUTPUT
36+
else
37+
echo "is_release=false" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Notify Central Publisher Portal
41+
if: steps.version.outputs.is_release == 'true'
42+
run: |
43+
token=$(echo -n "${{ secrets.NEXUS_USERNAME }}:${{ secrets.NEXUS_PASSWORD }}" | base64)
44+
curl -X POST \
45+
--max-time 30 \
46+
--fail-with-body \
47+
-H "Authorization: Bearer $token" \
48+
"https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/com.pkware.detekt?publishing_type=automatic"

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ line.
6363
6. Merge the release PR after approval, tag the commit on the main branch with
6464
`git tag -a X.Y.Z -m "X.Y.Z"`(X.Y.Z is the new version).
6565
7. Run `git push --tags`.
66-
8. Run `./gradlew publish` in the terminal or command line.
67-
9. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
68-
10. Update `gradle.properties` to the next SNAPSHOT version.
69-
11. Run `git commit -am "Prepare next development version."`
70-
12. Make a PR with your changes.
71-
13. Merge the next version PR after approval.
72-
73-
If step 8 or 9 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 8.
66+
8. Visit [Sonatype Nexus](https://central.sonatype.com/) and promote the artifact.
67+
9. Update `gradle.properties` to the next SNAPSHOT version.
68+
10. Run `git commit -am "Prepare next development version."`
69+
11. Make a PR with your changes.
70+
12. Merge the next version PR after approval.

import-extension/build.gradle.kts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ publishing {
7575
}
7676
repositories {
7777
maven {
78+
name = "MavenCentral"
7879
url = uri(if (version.toString().isReleaseBuild) releaseRepositoryUrl else snapshotRepositoryUrl)
7980
credentials {
8081
username = repositoryUsername
@@ -85,8 +86,15 @@ publishing {
8586
}
8687

8788
signing {
88-
// Signing credentials are stored locally in the user's global gradle.properties file.
89+
// Signing credentials are stored as secrets in GitHub.
8990
// See https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signatory_credentials for more information.
91+
92+
useInMemoryPgpKeys(
93+
signingKeyId, // ID of the GPG key
94+
signingKey, // GPG key
95+
signingPassword, // Password for the GPG key
96+
)
97+
9098
sign(publishing.publications["mavenJava"])
9199
}
92100

@@ -97,14 +105,14 @@ val Project.releaseRepositoryUrl: String
97105
get() =
98106
properties.getOrDefault(
99107
"RELEASE_REPOSITORY_URL",
100-
"https://oss.sonatype.org/service/local/staging/deploy/maven2",
108+
"https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2",
101109
).toString()
102110

103111
val Project.snapshotRepositoryUrl: String
104112
get() =
105113
properties.getOrDefault(
106114
"SNAPSHOT_REPOSITORY_URL",
107-
"https://oss.sonatype.org/content/repositories/snapshots",
115+
"https://central.sonatype.com/repository/maven-snapshots/",
108116
).toString()
109117

110118
val Project.repositoryUsername: String
@@ -113,6 +121,15 @@ val Project.repositoryUsername: String
113121
val Project.repositoryPassword: String
114122
get() = properties.getOrDefault("NEXUS_PASSWORD", "").toString()
115123

124+
val Project.signingKeyId: String
125+
get() = properties.getOrDefault("SIGNING_KEY_ID", "").toString()
126+
127+
val Project.signingKey: String
128+
get() = properties.getOrDefault("SIGNING_KEY", "").toString()
129+
130+
val Project.signingPassword: String
131+
get() = properties.getOrDefault("SIGNING_PASSWORD", "").toString()
132+
116133
val Project.pomPackaging: String
117134
get() = properties.getOrDefault("POM_PACKAGING", "jar").toString()
118135

0 commit comments

Comments
 (0)