Updated April 12, 2023
Introduction to Maven Deploy
Apache Maven is a building tool that also helps in performing other project management tasks such as dependency management and documentation. The build lifecycle of the maven is divided into multiple phases. Validate, compile, test, package, verify, install, and deploy. The deploy is the last phase of the maven lifecycle. In this phase, the build is completed and the current project is being copied to the remote repository. This makes the built project available for other projects to add as dependency or developers. In this topic, we are going to learn about Maven Deploy.
The deploy plugin in the maven is used in the deploy phase of the build lifecycle. In this article, we will learn about the maven deploy plugin, where is it used, that are the prerequisites to use it and how it can be done.
Deploy Plugin of Maven
The deployment is usually performed in the environments where integration and release of the projects are done. It is the action to add the project(s), the artifact(s), and all the related information to the remote place where remote repository is located so that it can be used and accessed by other projects and developers.
The repository is not just made of artifacts, it also contains various metadata, hash files like MD5 and SHA1, POM files, etc that need to be updated as well when a new deployment is being done along with copying the expected artifact(s). Maven deploy plugin makes sure that all this task is performed correctly.
If you want to deploy the artifact(s) there are certain things that you need to have before doing so that are as follows –
- Repository related information such as the location of the repository, the access mechanism, and method of transports like SFTP, SCP, and FTP or any other and the information about the user account that is required sometimes and is optional.
- Artifact(s) related information that you wish to deploy such as the packaging, artifact id, group id, classifier, and other things.
- Deployer – This is the actual strategy of methodology that will perform the deployment of the artifact(s).There are many ways in which this can be done such as using the methods that is specified by the system or implementing the wagon transport that helps in making it cross-platform.
All the above prerequisites and information is obtained from the command-line and pom files that are specified or implied. To obtain the credentials of user parsing of settings.xml can also be done.
Goals of deploy plugin
There are two goals defined for the deploy plugin to perform deployment that is as follows –
- deploy:deploy – It helps in the automatic installation of the artifact and its related information such as pom file, artifacts that are attached to the particular project. All the information that is related to the deployment is stored inside the pom file of the project.
- deploy:deploy-file – This goal is useful in the installation of a single artifact and its pom. Information about the artifact is obtained from the optionally specified pom file or command-line.
Besides the above two, there is one more goal for which the deploy plugin is helpful that is deploy:help which helps in displaying all the information related to maven deploy plugin for help. This goal can be called by using the following command to display the details of parameters –
mvn deploy:help -Ddetails=true -Dgoal=<goal-name>
For using the deploy plugin of maven the minimum requirements that your system should fulfill include maven 3.0 and JDK 1.7. It does not have any minimum memory or disk space mentioned for the plugin to work properly.
Using the maven-deploy-plugin
We need to specify the version and plugin in the <pluginManagement> tag of the pom.xml file to define the version of the plugin in parent pom and specify the version and plugin in the plugins section of the pom file to use the goals of the plugin by your project or your parent project.
You can do so by using the following snippet in your pom file.
<project> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.0.0-M1</version> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.0.0-M1</version> </plugin> </plugins> </build> </project>
It is very easy to deploy the project. You just need to fire the following command –
In most of the cases, the test phase is not required to be performed while deploying and releasing your project as this is the last stage of your project and it is obvious that the project has been tested previously if required. Hence, you can skip the test phase of the maven build lifecycle while deploying by using the command –
mvn clean deploy -Dmaven.test.skip=true
Usage and example of artifact deployment with FTP method
The maven deploy plugin can be used to deploy either files or projects to the remote repository for sharing it with other developers and projects. There are various methods can be used to deploy your artifact to the remote repository by using a maven deploy plugin.
One of the most basic ones is using the FTP to deploy artifacts in the maven project while using the deploy plugin. In this case, you need to mention the FTP server usage in the <distributionManagement> tag of the pom file and to pull in the artifacts you also need to mention it in extension tag of the <build> element inside your pom.xml file in the following way –
<distributionManagement> <repository> <id>sample-ftp-educba-repository</id> <url>ftp://repository.educba.com/samplerepository</url> </repository> </distributionManagement> <build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ftp</artifactId> </extension> </extensions> </build>
Besides that, you will have to mention user details and id along with configurations for FTP in your settings.xml file. This can be specified in the following way inside the <servers> tag of settings element, you will need to add the following snippet having server tag –
<server> <id>sample-ftp-educba-repository</id> <username>your_uname</username> <password>your_passwd</password> <configuration> <endpointChecking>false</endpointChecking> </configuration> </server>
Note that the id you mention in the server element inside the settings.xml file and id in your repository tag inside <distributionmanagement> element in pom file needs to be the same.
You can easily deploy a single artifact or multiple artifacts to the remote repository so that other developers and projects can use it with the help of deploy plugin provided in maven projects.
We hope that this EDUCBA information on “Maven Deploy” was beneficial to you. You can view EDUCBA’s recommended articles for more information.