Maven Release plugin, version plugins and snapshots - maven

I am trying to automate the release of interdependent projects. Here is the scenario. I have two projects: A and B. Project B has a dependency on project A. Here are the steps that need to happen in the automated procedure:
Release project A using maven-release-plugin. ( I know how to do this). Here is the sequence of goals I have defined:
release:clean release:prepare -DcommitByProject=true -DautoVersionSubmodules=true release:perform
Deploy the latest SNAPSHOT version of project A to the repository. (Using simply deploy is working. However there is a slight catch, which I've described below.)
Update the SNAPSHOT dependency version of project A in project B to the latest release version before doing a full release. In order to achieve this I've set the preparationGoals like this (clean verify versions:use-latest-versions versions:commit) in project B's POM file.
Everything seems to work fine.
Now what I want is that once the release is complete, Project A dependency in Project B to the latest SNAPSHOT version that was set during the release by the release:prepare plugin.
The solution I came up with was to do a maven deploy for project A SNAPSHOT right after the release:perform was executed. (New goal sequence for project A: release:clean release:prepare -DcommitByProject=true -DautoVersionSubmodules=true release:perform clean install deploy)
Then, I can execute a versions:use-next-snapshots at the end of the project B's release cycle.
(New goal sequence for project B: release:clean release:prepare -DcommitByProject=true -DautoVersionSubmodules=true release:perform versions:use-next-snapshots). Here I do restrict my versions plugin to handle only Project A dependencies.
The trouble is that when I execute the goals for Project A. Maven deploys the SNAPSHOT with the old version and not the incremented version. So if version before release for project A was 1.1-SNAPSHOT. The version after release is now 1.2-SNAPSHOT. The release version will be 1.1. However, project A snapshot version deployed is 1.1-SNAPSHOT and not 1.2-SNAPSHOT.
I am guessing that maven is not updating the pom in memory after the maven-release-plugin goals are executed.

have you considered making both projects belong to a parent project. then you release the parent project which in turn releases each module (sub project) automatically

Related

Jenkins artifactory release management plugin with mvn versions:use-releases

"mvn versions:use-releases (mvn goals)" remove the "SNAPSHOT" word on your dependencies, ONLY / DURING the specific build you've triggered, not modifying or parsing your pom.xml on the repo itself (like gitlab) this could be very helpful when using artifactory release management plugin because this process doesn't allow projects with SNAPSHOT word on pom.xml, however I have tried using the mvn versions:use-releases when doing a release on artifactory release plugin, but the build is failing due to the build read 1st the pom.xml (with snapshot) before executing the mvn goals that will remove the snapshot word, even I tried to put the mvn goals on the alternative maven goals and options under "enable artifactory release management"
is there any way to solve this?

Maven multi-module project only deploy -SNAPSHOT modules in mvn deploy

I have a snapshot and a release repository defined in the pom.xml of all modules
The modules in my project may be developed and updated independently, i.e. one may be updated (and hence be -SNAPSHOT) during development whereas all others are untouched with release versions
My release nexus repository prevents redeployment
Running mvn deploy will successfully deploy -SNAPSHOT projects to the snapshot repository as required but when it tries to reploy one of the unchanged modules the build fails because that module is already in the release repository
I do not want releases to be redeployable - once a release is deployed it is final
Is there a way to run "mvn deploy" such that all snapshot bundles do get deployed but release modules are skipped?

Maven- Deploy release version of jar

I am new to maven and I'm using the maven release plugin to do a release and the maven deploy to deploy it. What I am noticing is that when I do
mvn release:prepare it makes two commits, as it should be, with the first one being without the snapshot in the pom.xml and then a newer version in the pom.xml with the snapshot. However when I then do mvn deploy it deploys the snapshot jar to my internal repository. How will I get it to deploy the release version of my jar? Should I be checking out HEAD~1 and then do mvn deploy?
Your question is slightly unclear, but the goal to run after release:prepare is release:perform.
Depending on what you're trying to do, the install or deploy plugins may also be useful.
Sonatype, the people that run Maven Central, have a very helpful guide to using the release plugin, as well as other ways of releasing:
http://central.sonatype.org/pages/apache-maven.html#performing-a-release-deployment-with-the-maven-release-plugin

Jenkins maven-release-plugin

In Jenkins (latest), Maven 3.0.x, I have a project (Java source code).
I'm using M2 release plugin, which provides a nice "Perform Maven Release" button on the Jenkins job (left hand side pane on the Jenkins job's dashboard). Behind the scene / in Jenkins job's configuration, it calls: release:prepare release:perform goals.
When I'm click on "Perform Maven Release", it does it's job successfully (builds from 1.0.0-SNAPSHOT, run tests && if successful, make changes to pom.xml and put version as 1.0.0 as version ID, perform some more verification and make changes to pom.xml (what maven-release-plugin checks are etc), commit this change in version control, tag it with 1.0.0 as a "TAG" in version control, change pom.xml again to use 1.0.1-SNAPSHOT and commit it, then checkout from that tagged 1.0.0 release version tag which we just created, checkout it under /target/checkout folder, build relase 1.0.0 artifacts (jar/war/pom etc) and finally deploys it to the repository which you'd have mentioned inside ..... ... section.
<distributionManagement>
<repository>
<id>dev-artifactory</id>
<url>http://1.2.3.15:8081/artifactory/libs-release-local/</url>
</repository>
<snapshotRepository>
<id>dev-artifactory</id>
<url>http://1.2.3.15:8081/artifactory/libs-snapshot-local/</url>
</snapshotRepository>
</distributionManagement>
What I need is:
1) How can I make "Perform Maven Release" process to call a deployment to a server once x.x.x release artifacts are generated by the process above and run some Integration tests. This should happen before deployment of artifacts to a binary repository (Artifactory/Nexus) is performed by maven-release-plugin process. i.e. if you are putting artifacts in a release repository, then non-unit tests are also successful (not that artifacts are in libs-release-local repository in Artifactory and Integration tests are yet to be launched.
OR do I need to change ... to use libs-snapshot-local (Artifactory repository) and then run IT tests and finally if those tests are successful, move 1.0.0 release artifacts from libs-stage-local repository to libs-release-local repository.
I know I can put maven-release-plugin related settings in Maven's user's .m2/settings.xml (user global) or at M2_HOME/.m2/settings.xml (global) but at this point, that's not the question.
We have a Jenkins deployment for each environment (dev, qa, prod). We move the same artifacts across all environments using Promoted Builds, Copy Artifact, and Parameterized Trigger plugins. To see how they work together, read this post (How to promote a specific build number from another job in Jenkins?)
As per the release process, instead of Maven Release plugin, use Maven Promote plugin (http://java.jiderhamn.se/2016/05/04/announcing-maven-promote-plugin/) to release the artifact that is already built and tested (there are a lot of articles on maven release plugin's drawbacks). You can still use Jenkins M2 Release Plugin, but in it's configuration, Release goals and options, call mvn release:clean promote:prepare release:prepare instead. For more details: https://github.com/mjiderhamn/promote-maven-plugin/issues/2
Maybe you should consider taking a look at this article here: https://pragmaticintegrator.wordpress.com/2014/05/12/running-the-maven-release-plugin-with-jenkins/
With Jenkins Release plugin you could customize your release workflow to add specific steps once your M2 release is done.

Build Pipeline with Jenkins - M2 Release -> Deployment to JBoss AS

I am using Jenkins as CI environment and I want to have the ability to deploy the build artifacts directly to a JBoss AS 7.1.1 server. For releasing the Maven artifacts I am using the Jenkins M2 Release Plugin.
The project structure of the project which makes problems looks as follows:
artifact-parent-pom
webapp-module
theme-module
The maven goal jboss-as:deploy can only be called on webapp-module.
To deploy the webapp-module to the JBoss server on every build, I added a post-build step calling
mvn jboss-as:deploy
on the sub-module. This works perfectly for standard SNAPSHOT builds, but not for release builds.
When using the Jenkins M2 Release Plugin to release a new artifact version, the version number is already updated to the next SNAPSHOT-version when the post-build step is executed. I tried to deploy the release version directly at the release step, but this doesn't work, hence the goal jboss-as:deploy cannot be called on the parent-pom.
All Jeknins plugins i have found only support older versions of JBoss like
Deploy to container Plugin
JBoss Management Plugin
Is there an easy way to get this working?
I have found a workaround. I made two configurations, one for the SNAPSHOTS and one for the RELEASE builds. At the RELEASE build I added two post-steps both calling the goal version:set on the parent-pom but with different properties. This results in the following post-steps:
mvn newVersion=${MVN_RELEASE_VERSION}
mvn jboss-as:deploy
mvn newVersion=${MVN_DEV_VERSION}

Resources