How to automate the Deployment process in Maven

Last updated on May 27 2022
Mrinalini Pandey

Table of Contents

How to automate the Deployment process in Maven

Maven – Deployment Automation

In project development, normally a deployment process consists of the next steps −
• Check-within the code from all project in ongoing into the SVN (version control system) or source code repository and tag it.
• Download the complete source code from SVN.
• Build the application.
• Store the build output either WAR or EAR file to a common network location.
• Get the file from network and deploy the file to the production site.
• Updated the documentation with date and updated version number of the application.

Problem Statement

There are normally multiple people involved within the above-mentioned deployment process. One team may handle check-in of code, other may handle build and so on. It is very likely that any step may be missed out due to manual efforts involved and owing to multi-team environment. For example, older build may not be replaced on network machine and deployment team deployed the older build again.

Solution

Automate the deployment process by combining the next −
• Maven, to build and release projects.
• SubVersion, source code repository, to manage source code.
• Remote Repository Manager (Jfrog/Nexus) to manage project binaries.

Update Project POM.xml

We will be using Maven Release plug-in to create an automated release process.
For Example: bus-core-api project POM.xml.
<project xmlns = “http://maven.apache.org/POM/4.0.0”
xmlns:xsi = “http://www.w3.org/2001/XMLSchema-example”
xsi:schemaLocation = “http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd”>
<modelVersion>4.0.0</modelVersion>
<groupId>bus-core-api</groupId>
<artifactId>bus-core-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<scm>
<url>http://www.svn.com</url>
<connection>scm:svn:http://localhost:8080/svn/jrepo/trunk/
Framework</connection>
<developerConnection>scm:svn:${username}/${password}@localhost:8080:
common_core_api:1101:code</developerConnection>
</scm>
<distributionManagement>
<repository>
<id>Core-API-Java-Release</id>
<name>Release repository</name>
<url>http://localhost:8081/nexus/content/repositories/
Core-Api-Release</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-9</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<goals>deploy</goals>
<scmCommentPrefix>[bus-core-api-release-checkin]-<
/scmCommentPrefix>
</configuration>
</plugin>
</plugins>
</build>
</project>
In Pom.xml, next are the important elements we have used −

Sr.No. Element & Description
1 SCM

Configures the SVN location from where Maven will check out the source code.

2 Repositories

Location where built WAR/EAR/JAR or any other artifact will be stored after code build is successful.

3 Plugin

maven-release-plugin is configured to automate the deployment process.

Maven Release Plug-in

The Maven does the next useful tasks using maven-release-plugin.
mvn release:clean
It cleans the workspace in case the last release process was not successful.
mvn release:rollback
Rollback the changes done to workspace code and configuration in case the last release process was not successful.
mvn release:prepare
Performs multiple number of operations, such as −
• Checks whether there are any uncommitted local changes or not.
• Ensures that there are no SNAPSHOT dependencies.
• Changes the version of the application and removes SNAPSHOT from the version to make release.
• Update pom files to SVN.
• Run test cases.
• Commit the modified POM files.
• Tag the code in subversion
• Increment the version number and append SNAPSHOT for future release.
• Commit the modified POM files to SVN.
mvn release:perform
Checks out the code using the previously defined tag and run the Maven deploy goal, to deploy the war or built artifact to repository.
Let’s open the command console, go to the C:\ > MVN >bus-core-api directory and execute the next mvn command.
>mvn release:prepare
Maven will start building the project. Once build is successful run the next mvn command.
>mvn release:perform
Once build is successful you can verify the uploaded JAR file in your repository.
So, this brings us to the end of blog. This Tecklearn ‘How to automate the Deployment process in Maven’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Maven and build a career in DevOps domain, then check out our interactive, Maven Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Maven

Maven Training

About the Course

Tecklearn has specially designed this Maven Training Course to advance your skills for a successful career in this domain. The course will cover different components of Maven and how they are used in software development operations. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Maven.

Why Should you take Maven Training?

• The average salary for “ant maven” ranges from approximately $71,430 per year for Entry Level Engineer to $126,916 per year for Development Operations Engineer. – Indeed.com
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation

Maven

• Maven
• Maven Directory
• Maven Lifecycle
• Maven Dependencies
• Maven Repositories
• Phases and Goals

0 responses on "How to automate the Deployment process in Maven"

Leave a Message

Your email address will not be published. Required fields are marked *