What is Maven Release Plugin
This plugin is used to release a project with Maven, saving a lot of repetitive, manual work. Releasing a project is made in two steps: prepare and perform.
What we going to do
In this blog, we are going to discuss basic step Maven Release Plugin.
- We are going to configure pom.xml for Maven Release Plugin
- We are going to configure setting.xml in order to give Github authentication
- Finally, we are going to make tag release.
All the xml file and sample project will provide at the end of the blog. Here I do more of a practical guide than explaining. You can get to know more about Maven Release Plugin in their documentation. Here it is http://maven.apache.org/maven-release/maven-release-plugin/
Let’s get our hands dirty.
Configure pom.xml for Maven Release Plugin
In Order to do that we need to complete 3 things.
- Add Maven Release Plugin to pom.xml
- Add developerConnection using scm section.
- Add GitHub authentication using server.xml
Let’s Add Maven Release Plugin to pom.xml
First you need to add Maven Release Plugin as a dependency into pom.xml. Like below
<dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> </dependency>
Then you need to include its configurations into <build> tag in like below
<pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> <configuration> <checkModificationExcludes> <checkModificationExclude>pom.xml</checkModificationExclude> </checkModificationExcludes> </configuration> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins>
Now you have completed the first Step. Now let’s do the second one
Add developerConnection using scm section.
developerConnection is one of must do things to work Maven Release plugin. The developerConnection contains the URL of the Source Control Management system pointing to the folder containing this pom.xml This URL is prefixed with scm:[scm-provider] so the plugin can pick the right implementation for committing and tagging. The Maven SCM-page contains an overview all the supported SCMs, per SCM you can see how the URL should look like.
<scm> <developerConnection>scm:git:https://github.com/Menuka5/MavenPluginTest.git</developerConnection> <tag>HEAD</tag> </scm>
<developerConnection>scm:git:“This is url you need to clone your project”</developerConnection>
you can find it in your GitHub project. Like Below selected.
Now we need to complete our last step to final this.
Add GitHub authentication using server.xml
For that, you need to access setting.xml file which resides in your maven folder. First, you need to find out where is Maven folder. If you don’t know where exactly the location, you need to run below command in your terminal (in Ubuntu)
This command will return a result like below.
Now you know the location of maven you need to access setting.xml file which resides in below location.
maven -> conf -> settings.xml
But be aware if your settings xml file reside in /usr/share/maven then you need superuser powers to edit it. it can be done using command
sudo gedit /usr/share/maven/conf/settings.xml
Then you need to insert your Github credentials like below format into settings.xml under <servers> tag.
<server> <id>githubcredentials</id> <username>Github username</username> <password>Github password</password> </server>[\code] After that save the file and close it. Now you need add those Github credentials to pom.xml of the project. <properties> <project.scm.id>githubcredentials</project.scm.id> </properties>
Remember that <project.scm.id> is the <id> you gave in settings.xml <server>
if you followed me up correctly now your project is ready for tag release just run
mvn release:clean release:prepare
and check on releases tab in your Github project like this if tag went correctly or not.
If there is a tag release under the tag you gave, Congratulations.