Publishing By Using the Maven Plugin⚓︎
Publisher Early Access supports publishing via Maven. In order to do this, you
need to configure your project to use the
central-publishing-maven-plugin
.
Note
The plugin does not generate all of the prerequisites for a valid
bundle, so you'll want to follow the documentation for building
Javadoc and sources .jar
files and GPG
signature files. There are
additional metadata requirements (specifically required elements in your POM)
that the plugin will not enforce. Please see our
requirements documentation for guidance.
The plugin does generate the required checksums for files that are part of a bundle. See the below Plugin configuration options. By default, all acceptable checksums are generated (MD5, SHA1, SHA256 and SHA512).
Usage⚓︎
<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.6.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
</configuration>
</plugin>
</plugins>
</build>
Credentials⚓︎
It's required to configure your settings.xml
with your user token credentials.
You can get these credentials by generating a user
token.
<settings>
<servers>
<server>
<id>central</id>
<username><!-- your token username --></username>
<password><!-- your token password --></password>
</server>
</servers>
</settings>
Publishing⚓︎
Once your build is configured, running mvn deploy
will generate a bundle and
upload it to the Portal for validation. A successful publish will look similar
to the following:
$ mvn deploy
[INFO] Scanning for projects...
[INFO] Inspecting build with total of 1 modules
[INFO] Installing Central Publishing features
...
[INFO] --- central-publishing-maven-plugin:0.6.0:publish (injected-central-publishing) @ example ---
[INFO] Using Central baseUrl: https://central.sonatype.com
[INFO] Using credentials from server id central in settings.xml
[INFO] Using Usertoken auth, with namecode: XXXXXXX
[INFO] Staging 2 files
[INFO] Staging /central/tests/sonatype-central-example/pom.xml
[INFO] Installing /central/tests/sonatype-central-example/pom.xml to /central/tests/sonatype-central-example/target/central-staging/org/sonatype/central/test/example/1.0.0/example-1.0.0.pom
[INFO] Staging /central/tests/sonatype-central-example/target/example-1.0.0.pom.asc
[INFO] Installing /Users/sonatype/workspace/central/tests/sonatype-central-example/target/example-1.0.0.pom.asc to /Users/sonatype/workspace/central/tests/sonatype-central-example/target/central-staging/org/sonatype/central/test/example/1.0.0/example-1.0.0.pom.asc
[INFO] Pre Bundling - deleted /central/tests/sonatype-central-example/target/central-staging/org/sonatype/central/test/example/maven-metadata-central-staging.xml
[INFO] Generate checksums for dir: org/sonatype/central/test/example/1.0.0
[INFO] Going to create /central/tests/sonatype-central-example/target/central-publishing/central-bundle.zip by bundling content at /central/tests/sonatype-central-example/target/central-staging
[INFO] Created bundle successfully /central/tests/sonatype-central-example/target/central-staging/central-bundle.zip
[INFO] Going to upload /central/tests/sonatype-central-example/target/central-publishing/central-bundle.zip
[INFO] Uploaded bundle successfully, deployment name: Deployment, deploymentId: 9590fb21-a026-4451-9722-a7216b258f4d. Deployment will require manual publishing
[INFO] Waiting until Deployment 9590fb21-a026-4451-9722-a7216b258f4d is validated
[INFO] Deployment 9590fb21-a026-4451-9722-a7216b258f4d has been validated. To finish publishing visit https://central.sonatype.com/publishing/deployments
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.000 s
[INFO] Finished at: 2024-01-01T00:00:00-00:00
[INFO] ------------------------------------------------------------------------
Automatic Publishing⚓︎
In the minimal configuration as used above, manual publishing is required. This can be useful when testing how publishing works or if you wish to perform additional manual checks. Though
often, especially in CI builds, it's desired to automatically publish after upload and validation. This can be achieved by setting the autoPublish
configuration to true
.
<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.6.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
</configuration>
</plugin>
<plugins>
</build>
Wait for Publishing⚓︎
By default, the plugin will block and wait until after it has uploaded a bundle and the publishing server has acknowledged that the bundle was validated. If it's desired
to block and wait until after publishing has occurred the waitUntil
configuration needs to be set to published
. This will require Automatic Publishing.
<build>
<plugins>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.6.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
<waitUntil>published</waitUntil>
</configuration>
</plugin>
<plugins>
</build>
Plugin configuration options⚓︎
autoPublish⚓︎
Flag to enable auto publishing of a deployment. Meaning no manual intervention is required, if a deployment is considered valid, to publish it. This can be useful for CI builds
Default: false
checksums⚓︎
The plugin generates checksums for the files to be deployed. The following checksums could be used:
Value | Description |
---|---|
all | Will generate MD5, SHA1, SHA256 and SHA512 checksums. |
none | No checksums will be generated by this plugin. This can be usefull if other tooling is used to generate the checksums. Note: without checksums, validation might fail. |
required | Only MD5 and SHA1 checksums will be generated. |
Default: all
centralBaseUrl⚓︎
URL that the plugin uploads the bundle to generated by this plugin
Default: https://central.sonatype.com
deploymentName⚓︎
Name of the deployment that's used for uploading and deploying on the central url. If using the central.sonatype.com, this name will be visible on the Deployments page
Default: Deployment
excludeArtifacts⚓︎
The plugin can exclude, or more specifically, not add components by their artifactId
failOnBuildFailure⚓︎
Indicates if building is allowed to have the plugin fail before uploading and publishing occurs.
Default: true
ignorePublishedComponents⚓︎
The plugin can ignore, or more specifically, not add components that have already been published in the past to the bundle that will be uploaded and published.
When working with projects that are using a multi-module setup, and it's desired to publish only new or updated modules (for example parent, child1 and child2 are all published, and it's desired to publish a new version 1.0.1 of child2, but leave child1 and parent unchanged), this configuration will assure that previous published components will not be part of the bundle that will be uploaded and published (which normally would cause a publishing to fail).
Default: false
outputDirectory⚓︎
Name of the directory that the plugin will output the bundle file into
Default: central-publishing
outputFilename⚓︎
Name of the bundle file that the plugin will output as a result
Default: central-bundle.zip
publishCompletionPollInterval⚓︎
Deprecated use waitPollingInterval
instead
Default: 1000
publishingServerId⚓︎
ID of the server that you configured in your settings.xml
Default: central
skipPublishing⚓︎
For creating only the bundle but skipping uploading and publishing. This is useful for creating a bundle and manually uploading it through central.sonatype.com
Default: false
stagingDirectory⚓︎
Name of the directory the plugin will stage files
Default: central-staging
waitForPublishCompletion⚓︎
Deprecated use autoPublish
in combination with waitUntil
instead
Default: false
waitMaxTime⚓︎
Maximum amount of seconds to waitUntil
a state has been reached. Cannot be less than 1800 seconds.
Default: 1800
waitPollingInterval⚓︎
Amount of seconds between intervals before checking if a state has been reached. Cannot be less then 5 seconds.
Default: 5
waitUntil⚓︎
The plugin can wait until certain states have been reached. This can be useful if it's required to run a deployment async. The following states can be waited for:
Value | Description |
---|---|
published | Wait until the deployment is uploaded, validated and published. Failures from upload, validation or publishing will be in the console result output. |
uploaded | Wait until the deployment bundle has been uploaded to the central URL. Only upload failures will be reported, any validation failures will have to be checked separately (i.e. on https://central.sonatype.com). |
validated | Wait until the deployment bundle has been uploaded and validated. Failures from upload and validation will be in the console result output. |
Default: validated
Release Notes⚓︎
0.6.0⚓︎
- Support for Maven Password Encryption
0.5.0⚓︎
- Remove the configuration support for publishing via username/password credentials, as the API has removed support
0.4.0⚓︎
- Adjust code, tests, and dependencies to compile and run with Java 8
- Remove dependency on Central Publishing Client
0.3.1⚓︎
- Adjust pom to source and target Java 8
0.3.0⚓︎
- Correct configuration options and match with documentation on https://central.sonatype.org/
0.2.0⚓︎
- Use latest version of Central Publishing Client
- Remove dependency on snakeyaml
- Improve wait and auto publish logic for plugin
0.1.6⚓︎
- General updates and improvents to plugin
0.1.2⚓︎
- General updates and improvents to plugin
0.1.1⚓︎
- Initial public release to support
mvn deploy
for https://central.sonatype.com through Sonatype supported Maven Plugin