Skip to content

Commit c5737dc

Browse files
author
Samuel Abramov
committed
migrating to new publish pipeline
1 parent b800e2a commit c5737dc

File tree

4 files changed

+125
-13
lines changed

4 files changed

+125
-13
lines changed

.github/workflows/gradle.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,25 @@ jobs:
2222
run: chmod +x gradlew
2323
- name: Build with Gradle
2424
run: ./gradlew build
25+
26+
publish:
27+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
28+
needs: build
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v5
33+
- name: Set up JDK 21
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '21'
37+
distribution: 'adopt'
38+
- name: Grant execute permission for gradlew
39+
run: chmod +x gradlew
40+
- name: Publish to Maven Central
41+
env:
42+
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
43+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
44+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
45+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
46+
run: ./gradlew publishAllPublicationsToNmcpMavenJavaRepository

PUBLISHING.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Publishing to Maven Central
2+
3+
This document describes the new publishing process for EDUX library to Maven Central using the new Central Portal API.
4+
5+
## Background
6+
7+
As of November 2024, OSSRH (OSS Repository Hosting) reached end of life and was shut down. We have migrated from the legacy OSSRH staging API to the new Central Portal publishing method.
8+
9+
**Official Statement:** https://central.sonatype.org/pages/ossrh-eol/
10+
11+
## New Publishing Method
12+
13+
We now use the `com.gradleup.nmcp` Gradle plugin, which provides integration with the new Maven Central Portal API.
14+
15+
### Configuration
16+
17+
The publishing configuration is in `lib/build.gradle`:
18+
19+
```gradle
20+
plugins {
21+
// ... other plugins
22+
id 'com.gradleup.nmcp' version '0.0.8'
23+
}
24+
25+
nmcp {
26+
publish("mavenJava") {
27+
username = System.getenv("MAVEN_CENTRAL_USERNAME")
28+
password = System.getenv("MAVEN_CENTRAL_PASSWORD")
29+
publicationType = "USER_MANAGED" // Manual release control
30+
}
31+
}
32+
```
33+
34+
### Required Secrets
35+
36+
The following GitHub secrets must be configured:
37+
38+
1. **MAVEN_CENTRAL_USERNAME**: Username from Central Portal token
39+
2. **MAVEN_CENTRAL_PASSWORD**: Password from Central Portal token
40+
3. **SIGNING_KEY**: GPG private key for artifact signing
41+
4. **SIGNING_PASSWORD**: GPG key passphrase
42+
43+
### Central Portal Token Generation
44+
45+
1. Go to https://central.sonatype.com/account
46+
2. Generate a user token
47+
3. Use the generated username/password for `MAVEN_CENTRAL_USERNAME` and `MAVEN_CENTRAL_PASSWORD`
48+
49+
### Publishing Process
50+
51+
#### Automated (GitHub Actions)
52+
- Automatic publishing occurs on pushes to `main` branch
53+
- GitHub Action runs: `./gradlew publishAllPublicationsToNmcpMavenJavaRepository`
54+
- With `USER_MANAGED` setting, releases require manual approval on Central Portal
55+
56+
#### Manual Publishing
57+
```bash
58+
# Publish to Central Portal
59+
./gradlew publishAllPublicationsToNmcpMavenJavaRepository
60+
61+
# Check available tasks
62+
./gradlew tasks --all | grep nmcp
63+
```
64+
65+
### Publication Type Options
66+
67+
- **USER_MANAGED**: Artifacts are uploaded but require manual release approval in Central Portal
68+
- **AUTOMATIC**: Artifacts are automatically published after validation
69+
70+
### Verification
71+
72+
After publishing with `USER_MANAGED`:
73+
1. Log into https://central.sonatype.com/
74+
2. Navigate to deployments
75+
3. Review and approve the deployment for public release
76+
77+
### Migration Changes
78+
79+
- ✅ Removed legacy OSSRH repository configuration
80+
- ✅ Added `com.gradleup.nmcp` plugin
81+
- ✅ Updated GitHub Actions workflow
82+
- ✅ Fixed JUnit test dependencies (unrelated but needed for build)
83+
84+
### Troubleshooting
85+
86+
- Ensure all required secrets are configured in GitHub repository settings
87+
- Verify GPG signing key is properly formatted (include `-----BEGIN PGP PRIVATE KEY BLOCK-----` headers)
88+
- Check Central Portal deployment status at https://central.sonatype.com/

example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'io.github.samyssmile'
7-
version = '1.0.7'
7+
version = '2.0.0'
88

99
java {
1010
toolchain {

lib/build.gradle

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id 'signing'
55
id "me.champeau.jmh" version "0.7.2"
66
id 'com.github.ben-manes.versions' version '0.51.0'
7+
id 'com.gradleup.nmcp' version '0.0.8'
78
}
89

910
group = 'io.github.samyssmile'
@@ -43,10 +44,10 @@ dependencies {
4344
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:3.0.0-beta2'
4445

4546
// Test dependencies
46-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
47+
testImplementation platform('org.junit:junit-bom:5.11.3')
48+
testImplementation 'org.junit.jupiter:junit-jupiter'
4749
testImplementation 'org.mockito:mockito-core:5.11.3'
4850
testImplementation 'org.mockito:mockito-junit-jupiter:5.14.2'
49-
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.3'
5051
}
5152

5253
tasks.withType(Test) {
@@ -96,21 +97,22 @@ publishing {
9697
}
9798
}
9899
}
99-
repositories {
100-
maven {
101-
name = "sonatype"
102-
url = version.endsWith('SNAPSHOT') ? 'https://s01.oss.sonatype.org/content/repositories/snapshots/' : 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
103-
credentials {
104-
username = System.getenv("OSSRH_USERNAME")
105-
password = System.getenv("OSSRH_PASSWORD")
106-
}
107-
}
108-
}
109100
}
110101

111102
signing {
103+
required { gradle.taskGraph.hasTask("publish") }
104+
useGpgCmd()
112105
sign publishing.publications.mavenJava
113106
}
114107

108+
nmcp {
109+
publish("mavenJava") {
110+
username = System.getenv("MAVEN_CENTRAL_USERNAME")
111+
password = System.getenv("MAVEN_CENTRAL_PASSWORD")
112+
// Use USER_MANAGED for manual publishing control, or AUTOMATIC for auto-publish
113+
publicationType = "USER_MANAGED"
114+
}
115+
}
116+
115117

116118

0 commit comments

Comments
 (0)