The maven deploy plugin currently org.apache.maven.plugins:maven-deploy-plugin:3.1.0
is used to copy/deploy maven artifacts to a Maven Repo (like Maven Central or NEXUS). See https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html.
This plugin needs to know where you want your maven artifacts deployed and how to login to that website.
The plugin gets the login and URL from your POM or from a command line option.
From your POM file
When using your pom, Distribution Management defines where to deploy to.
In this approach, a pom.xml file (or parent.pom) defines the URL of the maven repository to use.
An example of this is shown below:
<distributionManagement>
<repository>
<id>corp1</id>
<name>Corporate Repository</name>
<url>https://corp1.example.com/repository/public</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<id>corp1-snapshot</id>
<name>Corporate Snapshot Repo</name>
<url>https://corp1.example.com/repository/snapshot</url>
</snapshotRepository>
Command line option -DaltDeploymentRepository
See https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html
In this approach, the command line specifies the login and URL of a maven repository to use.
The syntax for the -DaltDeploymentRepository
has for many years been the same. The syntax was: -DaltDeploymentRepository=id::layout::URL
.
id - referred to a server's <id>
value in a maven settings file (typically at $HOME/.m2/settings.xml).
layout - is nearly always default, and it refers to the format of the maven repository. Maven 1.x used one format and maven 2.x and higher used a different format. See also What does repository layout mean.
URL - refers to a maven repository to which the maven deploy plugin can write to.
How does maven decide when to use POM vs the command line option
Maven will automatically use the <snapshotRepository>
if
the version in the pom.xml file ends with -SNAPSHOT
. For example, <version>12.5.59-SNAPSHOT</version>
. Otherwise, the <repository>
information will be used.
A more detailed/complete description is here, Difference between altDeploymentRepository and altReleaseDeploymentRepository
Example
A user runs the following command:
mvn deploy -DaltDeploymentRepository=server.id::default::https://example.com/repository/public
For the above command, server.id
means the id of the server as defined in the $HOME/.m2/settings.xml
settings file. For example,
<servers>
<server>
<id>server.id</id>
<username>exampleuser</username>
<password>examplepass</password>
</server>
</servers>
The newer versions of the maven-deploy-plugin (versions 3.0 and higher) switched to a different syntax for the -DaltDeploymentRepository
option and that syntax simply drops the ::default
from the string. So the new syntax is:
-DaltDeploymentRepository=server.id::URL
So the login information and the URL are still provided, only the ::default
portion of the value was removed.
Things to be aware of
If you pass in the newer syntax server.id::URL
, but the maven application is still using the older maven deploy plugin (e.g., maven-deploy-plugin < 3.0), then you will get an error like:
. . . Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
This happens because the old maven plugin is looking for the older syntax. To fix this add ::default
to the command line option.
Switching to the version 3.x of the maven-release-plugin
To use the newer version you'll need something like this in your pom file.
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifiactId>
<version>3.1.0</version>
</plugin>
</plugins>
</build>