Maven - (Deploy|Distribution) Phase

Card Puncher Data Processing

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

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





Discover More
Card Puncher Data Processing
Maven - (Password|Credentials)

How to manage credentials: login password within Maven Encrypt the master password Saved it by creating the file m2_home/.m2/settings-security.xml And save it in the settings.xml...
Card Puncher Data Processing
Maven - (Remote Repository|Server)

Remote repository in maven A remote repository (or server) can be defined as: a source to resolve dependency (via HTTP) or as a target to deploy the artifact (via SCP) The definition dependent on...
Card Puncher Data Processing
Maven - Artifact - (Component|Module|Library)

in Maven. An Artifact is the data storage unit of a repository. It's at the same time: the distribution unit to distribute and the dependency unit to use (Ie artifacts can be transferred to...
Idea Maven Dependency Tree
Maven - Dependency

dependency management in Maven. Dependency are artifact where your software depends on. Dependency are defined in the pom.xml, section dependencies. When you build an application, Maven will search...
Card Puncher Data Processing
Maven - Distribution Management

The distribution Management pom.xml section is responsible to define: the remote repositories how to deploy the project's site and documentation....
Card Puncher Data Processing
Maven - Install (Local Package Installation)

Install is a phase that install the generated artifact in the local repository. deploy Plugin that can be used in this phase. install...
Card Puncher Data Processing
Maven - JRE (Including it in your distribution)

A JRE is just a dependency Therefore you can upload it to a repository and use it in your build. With a file named jre-1.7.80-windows-x64.zip, we will get the following artifact coordinates: ...
Card Puncher Data Processing
Maven - Lifecycle

A Build Lifecycle is Made Up of Phases. To call all phase, you only need to call the last build phase to be executed, deploy: If you call a build phase, it will execute not only that build phase, but...
Card Puncher Data Processing
Maven - Phase (Build lifecycle)

A phase is a step in the build lifecycle, which is an ordered sequence of phases. When a phase is given, Maven will execute every phase in the sequence up to and including the one defined. Phases are...
Card Puncher Data Processing
Maven - Plugin Development

How to develop a maven plugin with Java Annotation. (It's important for the configuration). The code result of this tutorial is on github. gerardnico/helloworld-maven-pluginhelloworld-maven-plugin ...



Share this page:
Follow us:
Task Runner