Maven‎ > ‎

Maven 3 Release

Using the release plugin under Maven 3 can sometimes cause some problems.

Firstly, a distribution management element must be defined, telling Maven where to deploy the release.
Such an element could look like the following:

<project>
...
 <distributionManagement>

   <repository>
     <id>praqma</id>
     <name>praqma</name>
     <url>scpexe://10.10.1.25:/var/www/repo/maven</url>
   </repository>
 </distributionManagement>
...
</project>

Out of the box Maven 3 only supports the file, http and https protocols, but these protocols does not always meet the requirements for deploying.
In this case scpexe is chosen for deployment. It seems that Maven uses the scpexe protocol when utilizing an external scp client and the scp protocol when using an internal.

<project>
...
  <build>
  ...
    <extensions>

    ...
     
<extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ssh-external</artifactId>
        <version>1.0</version>
      </extension>
    ...
    </extensions>
  ...
  </build>
...
</project>

The above <extension> element allows Maven to run an external ssh application. Besides adding this element to the pom, the implementing jar must be added to ${MAVEN_HOME}/lib.
The jar can be found at http://mvnrepository.com/artifact/org.apache.maven.wagon/wagon-ssh-external/1.0.
You can see the Maven installation directory with which mvn.

You can attach an scm to the release, which will update the remote repository with the new information and add a tag.
In this case Git with a remote repository at GitHub.com.

<project>
...
  <scm>

    <connection>scm:git:http://github.com/cool.git</connection>
    <developerConnection>scm:git:ssh://git@github.com/Praqma/cool.git</developerConnection>
    <url>https://github.com/Praqma/cool.git</url>
  </scm>
...
</project>


This will release the current version incrementing to the next SNAPSHOT, pushing the changes and adding a version tag to GitHub and deploying the artifact to the Maven repository.
Note that a valid GitHub certificate is required and a valid certificate to the Maven repository is also required. Plus the user needs write access to the repository directory. This could
be done creating a group, maven, and letting this group have write access. The user could then be added to that particular group.

If something goes wrong you can rollback like the following:
  • mvn release:rollback - rolls back the changes done in the pom and commits it to the scm
  • mvn release:clean - cleans the workspace
  • git tag - lists the tags, pick the one Maven made,
  • git tag -d <tag> - removes the tag from the local index
  • git push <remote> :<tag> - removes the tag from the remote, typically origin
  • git reset --hard HEAD^ - rolls back the repository, one commit at the time. Roll back to before Maven committed anything, typically two.
  • git push -f - push the rollback to the remote

Comments