Maven - (Deploy|Distribution) Phase

About

This deploy phase copies:

  • a (final) package
  • 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.

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 <distributionManagement/> in the pom.xml must be included with:

<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

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:

<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.

Documentation / Reference


Powered by ComboStrap