Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Maven Automated Deployment

Maven Automated Deployment

During project development, the deployment process includes the following steps:

Description

Typically, the development process mentioned above involves multiple teams. One team may be responsible for committing code, another for building, and so on. Due to manual operations and a multi-team environment, any step is likely to go wrong. For example, an older version was not updated on the network machine, and then the deployment team redeployed an earlier build.

Solution

Automated deployment is achieved by combining the following approaches:


Modify the project's pom.xml

We will use the Maven release plugin to create an automated release process.

For example, the pom.xml file of the bus-core-api project is as follows:

<

project

xmlns

=

"

http://maven.apache.org/POM/4.0.0

"

xmlns:xsi

=

"

http://www.w3.org/2001/XMLSchema-instance

"

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 the pom.xml file, some important element nodes we commonly use are shown in the table below:

element nodes Description
SCM Configure the SVN path from which Maven will check out the code.
repository The location of the built WAR, EAR, or JAR file, or the storage location of other artifacts generated after a successful source build.
Plugin Configure the maven-release-plugin to implement the automated deployment process.

Maven Release Plugin

Maven uses the maven-release-plugin to accomplish the following tasks.

mvn release:clean

Clean the workspace to ensure the latest release process proceeds successfully.

mvn release:rollback

If the previous release process was unsuccessful, roll back the modified workspace code and configuration to ensure the release process proceeds successfully.

mvn release:prepare

Perform various operations:

mvn release:perform

Switch the code to the previously tagged location and run the Maven deploy goal to deploy the WAR file or build the corresponding structure into the repository.

Open a command terminal, go to the C:\ > MVN >bus-core-api directory, and execute the following mvn command.

C:\MVN\bus-core-api>mvn release:prepare

Maven starts building the whole project. After a successful build, run the following mvn command.

C:\MVN\bus-core-api>mvn release:perform

After a successful build, you can verify that the JAR file uploaded to your repository is effective.