The ultimate goal of any project is the release. After development is complete and bugs are fixed, it is time to release the project. Different projects are released in different ways. Web projects are released by deploying them to the web server. Other projects may be packaged into executable JARs. Still others may be packaged as executables or installers. If the project is a library or a dependency used in other projects, then it needs to be made available suitably.
As we have seen before, we use the SNAPSHOT
version during development. When the project has to be released, this version now needs to be replaced with a concrete version.
One of the most advanced features of Maven is its support to do a project release. Let us explore this.
project-with-release
).<scm> <developerConnection>scm:git:https://bitbucket.org/maruhgar/apache-maven-cookbook</developerConnection> <url>https://bitbucket.org/maruhgar/apache-maven-cookbook</url> <tag>HEAD</tag> </scm>
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.1</version> </plugin> </plugins>
mvn release:prepare –DpushChanges=false
By default, changes made by the plugin are pushed to the repository. If you do not want that, set the pushChanges
configuration option to false
.
You could choose the default values for the release version, the SCM tag and new development version, or provide your values.
Maven runs a number of commands that modify the pom file. Then, it checks in the changes into the repository.
mvn release:perform –Dgoals=package –DlocalCheckout=true
By default, the perform
goal of the Maven Release plugin runs the deploy
goal to deploy the project to the specified repository. If you do not have a remote repository to deploy to, or want to run a different goal as part of the release, you can specify it using the goals
configuration. In the preceding case, we have set it to run the package
goal.
Also, to do the release, Maven checks out the tag created by the prepare
goal from the repository. If you want Maven to check out the local copy instead, you could do so by setting the localCheckout
configuration to true
.
target/checkout/project-with-release/target
folder:There are two steps to making a release—prepare and perform.
When the prepare goal of the Maven Release plugin is run, it does the following:
SNAPSHOT
dependenciesSNAPSHOT
project; you will be prompted to confirm or override the defaulttag
element to the scm
element and computes the value (by default, HEAD
)verify
goal to ensure that the changes do not break anythingSNAPSHOT
value (from 1.0-SNAPSHOT
; this would be 1.1-SNAPSHOT
); you will be prompted to confirm or override thisAs you can see, once the goal is met, you will have an updated SCM with a tag with the release version and the HEAD
with the next SNAPSHOT
version. A release.properties
file is also created. It contains information that is needed for the perform
goal.
The second platform does as follows:
release.properties
to check out from the SCM tag that was created earlierdeploy
)Once the build is successful, release.properties
and other backup files created by the Release plugin are removed.
3.138.105.215