You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: HELP.md
+364Lines changed: 364 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,3 +14,367 @@ While most of the inheritance is fine, it also inherits unwanted elements like `
14
14
To prevent this, the project POM contains empty overrides for these elements.
15
15
If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides.
16
16
17
+
18
+
# Publish an Open‑Source Java Library to Maven Central (2025 edition)
19
+
20
+
*An end‑to‑end, copy‑pasteable guide using a fictional org **OpenJavaLibs** and library **pojo-helper**. It covers the new Central Publisher Portal flow (tokens + the Central Publishing Maven Plugin), GPG signing, POM metadata, `settings.xml`, and optional CI with GitHub Actions.*
21
+
22
+
---
23
+
24
+
## 0) What you’ll need
25
+
26
+
***Java**: JDK 17+ (`java -version`)
27
+
***Maven**: 3.9+ (`mvn -v`)
28
+
***GPG**: `gpg --version` (for signing)
29
+
***Git & GitHub**
30
+
* A few minutes on **central.sonatype.com** to create a namespace and a **publishing token**
31
+
32
+
> Why this guide? As of 2024–2025, new (and migrated) projects publish via the **Central Publisher Portal** using **tokens** and the **Central Publishing Maven Plugin** — not the legacy OSSRH “staging” plugin.
33
+
34
+
---
35
+
36
+
## 1) Create your GitHub organization and repository
> You’ll use the **long key id** in Maven config. For CI, prefer importing the private key from a secret and passing the passphrase via env vars.
127
+
128
+
---
129
+
130
+
## 5) Create a Central‑ready `pom.xml`
131
+
132
+
This POM includes required metadata (**name, description, license, SCM, developers**), generates **sources** and **javadoc** JARs, signs artifacts with **GPG**, and wires the **Central Publishing Maven Plugin** (`org.sonatype.central:central-publishing-maven-plugin`).
133
+
134
+
> Replace names/URLs as appropriate. Keep `<groupId>` within your claimed namespace, e.g., `io.github.openjavalibs`.
> **Security tip:** Use Maven’s **encrypted passwords** for local dev, or provide credentials via CI secrets/env vars. The Central plugin supports Maven password encryption.
315
+
316
+
---
317
+
318
+
## 7) First local build (unsigned vs signed)
319
+
320
+
* Quick local build without signing (for development only):
321
+
322
+
```bash
323
+
mvn -q -Dgpg.skip clean verify
324
+
```
325
+
326
+
* Full release build (signs artifacts):
327
+
328
+
```bash
329
+
export GPG_PASSPHRASE='••••••••'# if you’re not using gpg-agent
330
+
mvn -q clean deploy
331
+
```
332
+
333
+
You should see the Central Publishing plugin stage a bundle and upload it. If `autoPublish` is **not** set, you’ll be asked to publish the validated deployment manually in the Portal UI.
334
+
335
+
---
336
+
337
+
## 8) Publish in the Portal (manual or automatic)
338
+
339
+
***Manual:** After `mvn deploy`, open the **Deployments** page in the Portal, review the validation, and **Publish**.
340
+
***Automatic (CI‑friendly):** In the POM plugin config, set:
341
+
342
+
```xml
343
+
<autoPublish>true</autoPublish>
344
+
<waitUntil>published</waitUntil>
345
+
```
346
+
347
+
This publishes automatically after validation and blocks until published (fail‑fast if validation fails).
348
+
349
+
---
350
+
351
+
## 9) Verify the release
352
+
353
+
* Search your coordinates on **central.sonatype.com** (Search).
354
+
* Check the canonical repository URL: `https://repo1.maven.org/maven2/io/github/openjavalibs/pojo-helper/`
355
+
* Consumers can now depend on it:
356
+
357
+
```xml
358
+
<dependency>
359
+
<groupId>io.github.openjavalibs</groupId>
360
+
<artifactId>pojo-helper</artifactId>
361
+
<version>1.0.0</version>
362
+
</dependency>
363
+
```
364
+
365
+
---
366
+
367
+
## 10) Optional: GitHub Actions CI for releases
368
+
369
+
Create `.github/workflows/release.yml` to publish on tag push.
0 commit comments