Skip to content

Commit becc9bf

Browse files
committed
Configure Maven Central and GitHub Packages publishing
- Add distributionManagement to pom.xml for Maven Central (ossrh) - Update publish.yml workflow: - Trigger on release creation instead of git tags - Use Maven instead of Gradle for publishing - Configure dual publishing to Maven Central and GitHub Packages - Add GPG signing support for Maven Central - Add proper permissions for GitHub Packages Required GitHub Secrets: - MAVEN_USERNAME: Sonatype OSSRH username - MAVEN_PASSWORD: Sonatype OSSRH password or token - GPG_PRIVATE_KEY: GPG private key for signing artifacts - GPG_PASSPHRASE: Passphrase for the GPG key GitHub Packages uses the automatic GITHUB_TOKEN (no manual setup needed).
1 parent 19eb232 commit becc9bf

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1-
name: Test and Publish to Maven
1+
name: Publish to Maven Central and GitHub Packages
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
4+
release:
5+
types: [created]
76

87
jobs:
9-
test-and-publish:
8+
publish:
109
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
1113
steps:
1214
- uses: actions/checkout@v6
13-
- name: Set up JDK
15+
16+
- name: Set up JDK for Maven Central
1417
uses: actions/setup-java@v5
1518
with:
1619
java-version: '17'
1720
distribution: 'temurin'
18-
- name: Grant execute permission for gradlew
19-
run: chmod +x ./gradlew
21+
server-id: ossrh
22+
server-username: MAVEN_USERNAME
23+
server-password: MAVEN_PASSWORD
24+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
25+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
26+
cache: 'maven'
27+
2028
- name: Run tests
21-
run: ./gradlew test
22-
- name: Publish to Maven
23-
run: ./gradlew publish
29+
run: mvn --batch-mode --update-snapshots test
30+
31+
- name: Publish to Maven Central
32+
run: mvn --batch-mode deploy -P sign-artifacts
2433
env:
2534
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
26-
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
35+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
36+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
37+
38+
- name: Set up JDK for GitHub Packages
39+
uses: actions/setup-java@v5
40+
with:
41+
java-version: '17'
42+
distribution: 'temurin'
43+
44+
- name: Publish to GitHub Packages
45+
run: mvn --batch-mode deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/${{ github.repository }}
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
</developer>
3232
</developers>
3333

34+
<distributionManagement>
35+
<repository>
36+
<id>ossrh</id>
37+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
38+
</repository>
39+
<snapshotRepository>
40+
<id>ossrh</id>
41+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
42+
</snapshotRepository>
43+
</distributionManagement>
44+
3445
<build>
3546
<plugins>
3647
<plugin>

0 commit comments

Comments
 (0)