Skip to content

Commit 04b58ba

Browse files
authored
Merge pull request #6952 from bndtools/copilot/extend-maven-docs-sonatype-mode
Document sonatypeMode configuration for Maven Central publishing via Sonatype Central Portal
2 parents 50247b1 + dc6b4d1 commit 04b58ba

File tree

1 file changed

+88
-4
lines changed

1 file changed

+88
-4
lines changed

docs/_plugins/maven.md

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ You can add `Group:Artifact:Version` coordinates in the `central.maven` file. Th
2020

2121
#### Release to Maven Central
2222

23-
Releasing to maven Central requires usually a couple of steps. For one you usually go through a staging repositroy like the staging nexus of sonartype. They perform a couple of checks and you manually have to clear the release via their web frontend.
23+
Releasing to Maven Central requires usually a couple of steps. For one you usually go through a staging repository like the staging nexus of Sonatype. They perform a couple of checks and you manually have to clear the release via their web frontend.
2424

25-
In case you version your bundles individually, e.g. sonartype will not complain if a Version of one Artifact in your staging repo already exists. The release will simply not work. Thus you can define a staging repository. The Release process will check against the releaseUrl if something already exists, but will upload to the staging URL.
25+
In case you version your bundles individually, e.g. Sonatype will not complain if a Version of one Artifact in your staging repo already exists. The release will simply not work. Thus you can define a staging repository. The Release process will check against the releaseUrl if something already exists, but will upload to the staging URL.
2626

2727
A configuration can look like this:
2828

@@ -33,6 +33,89 @@ A configuration can look like this:
3333
index=${.}/release.maven; \
3434
name="Release"
3535

36+
#### Release to Maven Central via Sonatype Central Portal
37+
38+
Maven Central now offers publishing through the [Sonatype Central Portal](https://central.sonatype.com/), which provides a streamlined publishing process. The MavenBndRepository plugin supports this with the `sonatypeMode` configuration property.
39+
40+
The `sonatypeMode` property controls how artifacts are published to Maven Central through the Sonatype Central Portal API:
41+
42+
* **`none`** (default) - Standard Maven repository behavior without special Sonatype Portal handling
43+
* **`manual`** - Artifacts are uploaded to Sonatype Central Portal for validation, but publishing must be done manually via the Sonatype web interface
44+
* **`autopublish`** - Artifacts are automatically published to Maven Central after successful upload and validation
45+
46+
##### Authentication
47+
48+
Publishing to Sonatype Central Portal requires authentication using a Bearer Token. Configure this in the [-connection-settings] instruction:
49+
50+
# Define your Bearer Token (typically from environment variable)
51+
sonatype_bearer: '${env;SONATYPE_BEARER;}'
52+
53+
# Configure connection settings
54+
-connection-settings.sonatype:\
55+
server; id = https://central.sonatype.com/api/v1/publisher/upload;\
56+
password = ${sonatype_bearer};\
57+
verify = false
58+
59+
The Bearer Token can be obtained from your [Sonatype Central Portal account](https://central.sonatype.org/publish/generate-portal-token/).
60+
61+
##### Configuration Examples
62+
63+
**Example 1: Automatic Publishing**
64+
65+
This configuration automatically publishes artifacts to Maven Central after upload and validation:
66+
67+
sonatype_bearer: '${env;SONATYPE_BEARER;}'
68+
69+
-connection-settings.sonatype:\
70+
server; id = https://central.sonatype.com/api/v1/publisher/upload;\
71+
password = ${sonatype_bearer};\
72+
verify = false
73+
74+
-plugin.release = \
75+
aQute.bnd.repository.maven.provider.MavenBndRepository; \
76+
releaseUrl = https://central.sonatype.com/api/v1/publisher/upload; \
77+
snapshotUrl = https://central.sonatype.com/repository/maven-snapshots; \
78+
index = ${.}/release.maven; \
79+
name = "Maven Central"; \
80+
sonatypeMode = autopublish
81+
82+
**Example 2: Manual Publishing with Staging**
83+
84+
This configuration uses a staging URL and requires manual publishing approval:
85+
86+
sonatype_bearer: '${env;SONATYPE_BEARER;}'
87+
maven_central: https://repo.maven.apache.org/maven2/
88+
89+
-connection-settings.sonatype:\
90+
server; id = https://central.sonatype.com/api/v1/publisher/upload;\
91+
password = ${sonatype_bearer};\
92+
verify = false
93+
94+
-plugin.release = \
95+
aQute.bnd.repository.maven.provider.MavenBndRepository; \
96+
releaseUrl = ${maven_central}; \
97+
stagingUrl = https://central.sonatype.com/api/v1/publisher/upload; \
98+
snapshotUrl = https://central.sonatype.com/repository/maven-snapshots; \
99+
index = ${.}/release.maven; \
100+
name = "Maven Central Staging"; \
101+
sonatypeMode = manual
102+
103+
When `stagingUrl` is specified with `sonatypeMode`, the plugin:
104+
1. Checks the `releaseUrl` (Maven Central) to verify the artifact doesn't already exist
105+
2. Uploads to the `stagingUrl` (Sonatype Portal) for validation
106+
3. In `manual` mode, waits for manual approval via the [Sonatype web interface](https://central.sonatype.com/publishing)
107+
108+
**Example 3: Local Repository Only**
109+
110+
This configuration disables Sonatype Portal integration:
111+
112+
-plugin.release = \
113+
aQute.bnd.repository.maven.provider.MavenBndRepository; \
114+
releaseUrl = file:///path/to/local/repo; \
115+
index = ${.}/release.maven; \
116+
name = "Local Release"; \
117+
sonatypeMode = none
118+
36119

37120

38121
### Use of .m2 Local Repository
@@ -80,11 +163,12 @@ The class name of the plugin is `aQute.bnd.repository.maven.provider.MavenBndRep
80163
|------------------|-------|---------|-------------|
81164
| `releaseUrl` | `URI` | | Comma separated list of URLs to the repositories of released artifacts.|
82165
| `snapshotUrl` | `URI` | | Comma separated list of URLs to the repositories of snapshot artifacts.|
83-
| `stagingUrl` | `URI` | | A single URL to the repositories staging repository. THis is required, e.g. for a release to maven central, which usually goes through a staging repository.|
166+
| `stagingUrl` | `URI` | | A single URL to the repositories staging repository. This is required, e.g. for a release to maven central, which usually goes through a staging repository.|
167+
| `sonatypeMode` | `none`\|`manual`\|`autopublish` | `none` | Controls how artifacts are published to Maven Central via the Sonatype Central Portal. `none`: standard Maven repository behavior; `manual`: upload for validation but requires manual publishing approval; `autopublish`: automatically publish after validation. Requires Bearer Token authentication via [-connection-settings]. |
84168
| `local` | `PATH`| `~/.m2/repository` | The file path to the local Maven repository. |
85169
| | | | If specified, it should use forward slashes. If the directory does not exist, the plugin will attempt to create it.|
86170
| | | | The default can be overridden with the `maven.repo.local` System property.|
87-
| `readOnly` | `true|false` | `false` | If set to _truthy_ then this repository is read only.|
171+
| `readOnly` | `true`|`false` | `false` | If set to _truthy_ then this repository is read only.|
88172
| `name` | `NAME`| `Maven` | The name of the repository.|
89173
| `index` | `PATH`| `cnf/<name>.mvn` | The path to the _index_ file. The index file is a list of Maven _coordinates_.|
90174
| `tags` | `STRING`| | Comma separated list of tags. (e.g. resolve, baseline, release) Use a placeholder like &lt;&lt;EMPTY&gt;&gt; to exclude the repo from resolution. The `resolve` tag is picked up by the [-runrepos](/instructions/runrepos.html) instruction.|

0 commit comments

Comments
 (0)