Maven release:branch - maven

I have a maven multi module project.
When the code is development complete, we would want to write a branch build job in Jenkins which branches the code, increment the pom versions in the trunk, and remove the
-SNAPSHOT from the pom versions in the branch.
So, if the trunk is 2.2-SNAPSHOT, by the end of the operation, the trunk should be 2.3-SNAPSHOT, and the newly created branch should have poms with 2.2.
When I use release:branch the trunk is getting updated but it's not removing the -SNAPSHOT from the poms in the branch.
Please let me know if you have any ideas of achieving this.
Thanks in advance.

From Maven Release plugin: Create a branch
By default, the POM in the new branch keeps the same version as the local working copy, and the local POM is incremented to the next revision. If you want to update versions in the new branch and not in the working copy, run:
mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true -DupdateWorkingCopyVersions=false
Note: This can be useful if you want to create a branch from a tag
As an alternative, you might want to try the Versions Maven plugin:
mvn versions:set versions:commit -DnewVersion=2.2.0
You would still need to create the branch by hand though...

Related

Maven release from a branch by jenkins

I have to perform a maven release from branch with Jenkis and tag the RELEASE.At the same time, i need to update the version (new SNAPSHOT) on trunk.
For Example:
/trunk contains Module_1.0.0-SNAPSHOT
/branches/Module_1.0.0-SNAPSHOT
After Perform Maven Release on /branches/Module_1.0.0-SNAPSHOT
/trunk contains Module_1.0.1-SNAPSHOT
/tag/Module_1.0.0-RELEASE
Setting maven-release-plugin and scm (url, connection, developerConnection), /tag/Module_1.0.0-RELEASE and new version on branch go right way.
But, even with developerConnection pointing to trunk doesn't udpate the version on trunk.
How could I achieve that?
thank's in advance.
If you run the Maven release plugin on your branch (/branches/Module_1.0.0-SNAPSHOT), it will:
Update the version number on this branch (1.0.0-SNAPSHOT --> 1.0.0)
Apply a tag on this branch (tag/1.0.0 or something like that)
Move your branch to 1.0.1-SNAPSHOT
Even if you set the developerConnection property, the Maven release plugin will not update the version number of your trunk branch.
If you want to increase the version number on the trunk, you have to release from the trunk (or release from the branch + merge your branch to your trunk).

Is maven release:branch supposed to update scm url of the branch?

I have this in my pom:
<scm>
<connection>scm:javasvn:http://url.com/repo/myProject/trunk</connection>
<developerConnection>scm:javasvn:http://url.com/repo/myProject/trunk</developerConnection>
<url>http://url.com/websvn/listing.php?repname=repo&path=/myProject/trunk</url>
</scm>
When I run:
mvn release:branch -DbranchName=myBranch
It creates successfully the branch here :
http://url.com/repo/myProject/branches/myBranch
But when I look into the pom.xml of this branch, the "scm" part remains the same as the trunk
<scm>
<connection>scm:javasvn:http://url.com/repo/myProject/trunk</connection>
<developerConnection>scm:javasvn:http://url.com/repo/myProject/trunk</developerConnection>
<url>http://url.com/websvn/listing.php?repname=repo&path=/myProject/trunk</url>
</scm>
Doc says:
Transform the SCM information in the POM to include the final
destination of the tag
Isn't the plugin supposed to replace "/trunk" by "/branches/myBranch"? Or are we supposed to do this manually?
The plugin replaces "trunk" by the "branches/myBranch" but don't switch your working copy. In the new created branch, viewing the remote pom.xml the scm info should have changed for that branch. maven:release fails if it cannot commit the changes.
r1643
[maven-release-plugin] prepare for next development iteration
---------------------
r1642
[maven-release-plugin] copy for branch a-project-1.0
---------------------
r1641
[maven-release-plugin] prepare branch a-project-1.0
---------------------
Is your svn log looking like this at the revision you created the branch?
In this example, r1641 changed the pom scm info from "trunk" to "branches/a-project-1.0".
r1642 copied the trunk to the branch, creating it.
r1643 changed the pom scm info from "branches/a-project-1.0" to "trunk" again so you remain at trunk in your working copy.
When I've used maven release and it failed, always has shown an error at the command line and left temporal files at my working copy that have to be deleted or cleaned with mvn --batch-mode release:clean.
Try changing your scm.url to "http://url.com/repo/myProject/trunk" instead of "http://url.com/websvn/listing.php?repname=repo&path=/myProject/trunk" (I don't think maven can change your current url parameter)
Then go again with: mvn --batch-mode -DbranchName="A_TEST" -Darguments="-DskipTests=true"
and check console errors, the svn log at the svn projects root folder, and also check for local working copy modifications.
If all should have been OK and it's not, check your maven runtime version. I've got some problems working with maven:release and maven 3.0.5 when releasing tags. I only use maven 3.1+ for branching/releasing automation purposes.
I replaced
scm:javasvn:http://...
with
scm:svn:http://...
And the transformation is done now.

Maven-release plugin: Branch without snapshot in version

I want to automate our branching process and for that i am using maven-release-plugin.
Following command is used for branching:
mvn --batch-mode release:branch -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=$MoveWorkingCopyToNextVersion
-DautoVersionSubmodules=true -Darguments="-DskipTests"
-DreleaseVersion=$BranchVersion -DbranchName=$BranchVersion
-DscmCommentPrefix=$ReleaseJira:
-Dusername=$BuildUser -Dpassword=$BuildUserPassword
My problem is that with above command version of pom created in branch is "BranchVersion-SNAPSHOT" while i want pom version in branch should be "BranchVersion" i.e. it should not contain snapshot.
I know this is not standard approach but our current release process will not work if branch contains "SNAPSHOT".
Any suggestions?
If you don't get updateVersionsToSnapshot working could you use the versions plugin afterwards to set the version on the Pom
http://mojo.codehaus.org/versions-maven-plugin/set-mojo.html

Branch through maven from subversion tag with correct developerConnection

I am trying to create a branch from a tag with maven but the developerConnection property is not updated. How do I do this through maven or editing the pom.xml file manually?
We use subversion for scm and maven for build/release. I want to create a branch from the latest tag (release). We will use the branch for maintenance of the code, including bug fixes, and continue developing on the trunk. (I know that discussion of developing on trunk versus on branch is involved, and I don't want to open that up.)
When I use release:branch to create the branch, the developerConnection property refers to the tag that I checked out of to create my working copy. I want it to point to the branch.
I checked out the latest tag. (foo-80.0.8)
From the command line in the working copy directory of that tag, I ran:
mvn release:branch -DbranchName=foo-80.0.8.1.x -DupdateWorkingCopyVersions=false
(The .1.x refers to the 1 st branch with x as a placeholder indicator for branch version.)
In the resulting pom.xml in the branch on the repository, the developerConnection property was set to
...Foo/tags/foo-80.0.8 (I omitted the beginning of the URL to prevent the automatic hyperlink.) I want it to be ...Foo/branches/foo-80.0.8.1.x
I tried again, but this time, I edited the pom.xml file, and changed developerConnection to ...Foo/branches/foo-80.0.8.1.x. After running mvn release:branch ..., developerConnection in the pom.xml file still pointed to the tag.
UPDATE:
I took #twomey1's suggestion. (Thanks!) Now developerConnection points to ...\tags\foo-80.0.8.1.x which is not the original tag (good), but that tag doesn't exist (bad). I checked out a fresh copy of the new branch, modified pom.xml to point to the branch, and committed the change. When I tried mvn release:prepare I got this error message:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-release-plugin:2.0-beta-7:prepare (default-cli) on
project foo: You don't have a SNAPSHOT project in the reactor projects list.
UPDATE:
#twomey1's comment about SNAPSHOT helped. Using -DupdateVersionsToSnapshot on the command line, I got release:prepare to go forward but there still seems to be confusion with tags and branches. Again, my workflow:
Run svn checkout https:.../tags/foo-80.0.8.
Run mvn -DupdateVersionsToSnapshot=true -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=false -DbranchName=foo-80.0.8.1 release:branch from the working copy of the tag that was just checked out.
Run svn checkout https:.../branches/foo-80.0.8.1 from the parent directory of the working copy.
Run mvn release:prepare from the working copy of the branch that was just checked out.
Then I get a svn error passed from maven that tag foo-80.0.8.1 already exists. I want to create a release from the branch which should not conflict. The developerConnection property still points to ...\tags\foo-80.0.8.1 which doesn't exist.
UPDATE:
I repeated with this difference, I added .1 to the end of the release version, the SCM release tag, and the portion of the development version before SNAPSHOT. This seems to work. I did this during mvn release:prepare.
From the official release plugin documentation
By default, the POM in the new branch keeps the same version as the
local working copy, and the local POM is incremented to the next
revision. If you want to update versions in the new branch and not in
the working copy, run:
mvn release:branch -DbranchName=my-branch -DupdateBranchVersions=true
-DupdateWorkingCopyVersions=false
Note: This can be useful if you want to create a branch from a tag
http://maven.apache.org/maven-release/maven-release-plugin/examples/branch.html
I think you are just missing -updateBranchVersions=true from your command

Maven Release: Prepare/Perform after Rollback incorrectly succeeds with wrong content

We use Maven with Subversion internally. We also use Maven's Release plugin. We noticed the issue described below when running through the following (correct, I presume) steps.
1. We run release:prepare:
Maven updates the trunk version to 1.0.0.
Maven runs svn copy trunk/myproject tags/myproject-1.0.0, thus creating tag myproject-1.0.0.
Maven updates the trunk version to 1.0.1-SNAPSHOT.
2. We run release:rollback:
Maven resets the trunk version to 1.0.0-SNAPSHOT.
Maven does not remove the tag, because Maven doesn't do this kind of stuff.
3. We commit more changes to trunk, obviously against version 1.0.0-SNAPSHOT.
4. We run release:prepare again:
Maven updates the trunk version to 1.0.0.
Maven runs svn copy trunk/myproject tags/myproject-1.0.0, thinking it created tag myproject-1.0.0 out of the latest trunk. But, alas, Subversion (1.6 and 1.7 alike) will instead create tags/myproject-1.0.0/myproject on Maven's behalf.
5. We run release:perform:
Maven checks out the contents of tag myproject-1.0.0.
Maven builds the contents and deploys the result to Nexus.
The problem is obvious: the change in step 3 did not make it into the tag. We are now releasing 1.0.0 without the change in it.
The questions are: How can we fix this? Is Maven's release rollback feature inherently broken?
In fairness, rollback should reset the project and SCM to a state that allows a second prepare to occur. This includes removing the tag. The answer is now apparent (Googling "maven release rollback remove tag"):
http://maven.apache.org/maven-release/maven-release-plugin/examples/rollback-release.html:
The created branch/tag in SCM for the release is removed. Note: This
is not yet implemented so you will need to manually remove the
branch/tag from your SCM. For more info see MRELEASE-229.
The resolution would then be to force release:rollback to include a command to delete the SCM tag using something like org.codehaus.mojo:exec-maven-plugin. Short of this, wrap rollback inside a script that does that externally.
As you've discovered, release:rollback doesn't have a whole lot of utility when it doesn't clean up SCM. What our shop has done is setup our Jenkins automation to run "mvn release:prepare release:perform" in combination with the Jenkins M2 Release Plugin.
If it fails we need to delete the tag in Subversion but, then again, we would have to do this anyway with rollback.

Resources