About
This deploy phase copies:
- a (final) package
- a web site
- or the Javadoc documentation
to a remote repository for sharing with other developers and projects.
In most project builds, the deploy phase of the build lifecycle is implemented using the deploy:deploy mojo
See also: the install phase to install your software in a local repository.
Articles Related
Configuration
The whole configuration is done in the pom.xml file
Define the plugin version
<build>
<!-- To define the plugin version in your parent POM -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
...
</plugins>
</pluginManagement>
<!-- To use the plugin goals in your POM or parent POM -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
...
</plugins>
</build>
Define the (remote) repository in distributionManagement
To enable the deploy plugin to function, a valid in the pom.xml must be included with:
- a tag (mandatory) defining the remote repository location for your artifact.
- a location if you want to separate snapshot artifacts from release artifacts.
- a section to deploy a project website. See Site
<distributionManagement>
<repository>
<id>myRepositoryId</id>
<name>Repository name</name>
<url>Host to Company Repository</url>
</repository>
<snapshotRepository>
<id>mySnapshotRepositoryId</id>
<name>Snapshot Repository name (For instance: Internal Release)</name>
<url></url>
</snapshotRepository>
<site>
<id>mySiteRepositoryId</id>
<name>my Site Name</name>
<url>myURL</url>
</site>
</distributionManagement>
Url follows the URI specification and specifies both the transport protocol (scheme) and the location to be used to transfer a built artifact
- external ssh client: scpexe://repository.mycompany.com/repository
- local file: file:/C:/m2-repo
- scp or sftp: scp://[email protected]:port/path/to/repo
- http: http://server:port/path/
- svn: scm:svn:https://server:port/path/
Add a file transfer method (connector)
Maven Wagon is a file (transfer|transport) application with modules (FTP, SSH, …)
For SSH (scp, sftp), you need to use the following module:
- without third client: The wagon-ssh artifactId add the SSH transport with JSCH implementation (no need of external ssh client).
- with a client: the wagon-ssh-external artifact must be used.
<build>
<extensions>
<!-- Enabling the use of SSH -->
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
</build>
Execute
deploy a build artifact
In most cases, the deploy mojo is invoked when you call the deploy phase of the default build lifecycle.
mvn deploy
deploy a third party artifact
Artifacts which are not built using Maven can be added to any remote repository using the deploy-file.
mvn deploy:deploy-file -Durl=file://C:\m2-repo \ (or scp://host.com/path/to/repo)
-DrepositoryId=some.id \
-Dfile=your-artifact-1.0.jar \
[-DpomFile=your-pom.xml] \
[-DgroupId=org.some.group] \
[-DartifactId=your-artifact] \
[-Dversion=1.0] \
[-Dpackaging=jar] \
[-Dclassifier=test] \
[-DgeneratePom=true] \
[-DgeneratePom.description="My Project Description"] \
[-DrepositoryLayout=legacy] \
[-DuniqueVersion=false]
where:
- URL where the artifact will be deployed. Example:
- file:///C:/m2-repo for a local repository
- or scp://host.com/path/to/repo for a remote repository. You need to add the ssh extension
- repositoryId default to remote-repository. Define in settings.xml. See Maven - (Remote Repository|Server)
- the groupId, artifactId, version and packaging informations are automatically retrieved from the given pom.