maven release-plugin usage in non-interactive mode - maven

I’m confused as to how the version number in a pom file and the system properties like -DdevelopmentVersion=2.0-SNAPSHOT and -DreleaseVersion=1.2 work when maven is run in non-interactive mode.
When I run mvn –B release:prepare –Dtag=1.2 -DdevelopmentVersion=2.0-SNAPSHOT -DreleaseVersion=1.2 for a pom.xml with <version>1.0-SNAPSHOT</version> and <packaging>jar</packaging> the resulting jar file uses the pom version number not the command line version, i.e xxx-1.0-SNAPSHOT.jar .
Is this the expected behaviour and if so what is the point of specifying the versions on the command line ?

You should be aware that the release:prepare is the first part of the release process. Afterwards you need to give release:perform which will checkout the created tag from version control and start the build for the artfiact whcih will be really released.

So I found my mistake:
Before running the example release:prepare in my question I had carried out a dryRun i.e. using the option-DdryRun=true .
This had created a release.properties file which was be used by subsequent release:prepare commands until it was cleaned up using release:clean

Related

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

Maven: change version properties in pom.xml

I have a Maven pom.xml, I build project and release project deploy with Jenkins.
But before and after build "release version" we need set my version in
For example:
I have in pom.xml
<properties>
<version-own>0.0.21-SNAPSHOT</version-own>
</properties>
before release I need set like this
<properties>
<version-own>0.0.25</version-own>
</properties>
after release I need set like this
<properties>
<version-own>0.0.27-SNAPSHOT</version-own>
</properties>
How can this be done?
If you don't have to use your own version property, consider the following that will operate on your <project><version>0.0.21-SNAPSHOT</version></project> element:
mvn versions:set versions:commit -DnewVersion="0.0.25"
That will modify your pom and adjust the version to your liking. You'll likely want to commit this change to your source code control repository, for this the scm plugin's scm:checkin goal works just fine (assuming you want this to be automated):
mvn scm:checkin -Dincludes=pom.xml -Dmessage="Setting version, preping for release."
Then you can perform your release (I recommend the maven-release-plugin), after which you can set your new version and commit it as above.
The versions plugin is your friend. Scripting the above would likely involve some parameterized build, or preferably the groovy plugin for jenkins which allows you to get the maven-specific build variables.
For starters, you can do it by hand. If your build follows maven conventions well, you could probably leverage one of a couple of maven plugins that exist for helping with the management of version numbers.
The maven-versions-plugin helps automate manual changes to version numbers. It has nice CLI commands to help tune up your poms before doing releases.
Then there's the maven-release-plugin that automates the whole process of cutting a release. It will change your snapshot to a release version, then roll it to the next snapshot after the release build. During all this process it commits discrete versions of the poms to source control.
Again, the secret to seeing success in the more automated bits of the maven community is whether your build is doing things the maven way or not. Hacked, highly tweaked, non-conventional builds usually have a lot of barriers to successful use of the release plugin.
There is one way to to that easily. With one command you can change whichever part you want:
For cut and paste:
mvn build-helper:parse-version versions:set -DbuildNumber=555 '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${buildNumber}'
For clarity:
mvn build-helper:parse-version versions:set -DbuildNumber=555
'-DnewVersion=
${parsedVersion.majorVersion}
.${parsedVersion.minorVersion}
.${parsedVersion.incrementalVersion}
-${buildNumber}'
This is a concise example how to update versions in one go with build values
Build-helper plugin supports regex replacements, and can even parse version numbers if need be.
http://www.mojohaus.org/build-helper-maven-plugin/
There is something like parsedVersion.nextIncrementalVersion
mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit
Looking at this comment you are describing that you are using this version to provide a dependency. maven-release-plugin should help you manage the versions for you. So provide that plugin in your pom.xml.
And for the step of manually providing the release and development version, create a job in jenkins which will have 2 string parameters:
developmentVersion
releaseVersion
Add "Invoke top-level Maven targets" build step to execute the releasing (for example):
clean release:clean release:prepare release:perform -DdevelopmentVersion=${developmentVersion} -DreleaseVersion=${releaseVersion}
When building the job, it will prompt you to insert both the developmentVersion and releaseVersion.
Cheers,
Despot

Unable to test Jenkins plugin

I am actually trying to develop a Jenkins plugin using maven but I am unable to test it.
I created my project with the command mvn -cpu hpi:create. I called the project jenkins-plugin-tutorial. I packaged it with mvn package or mvn install and run the Jenkins server with mvn hpi:run.
By default, there is a HelloWorlBuilder for testing purpose that should appear at the Jenkins configuration page (Jenkins Menu -> Manage Jenkins -> Configure System) or under the Build section, but it does not display.
I followed these two tutorials (here and here) step by step many times by making sure that I do not make a mistake but it still dont work.
Maybe I have made something wrong. Can somebody gives me some hint how to correct my errors.
In pom.xml, try changing parent to this:
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.454</version>
</parent>
I just did quick test with that hpi:create, and it worked for me, I got both global and job config things as expected, but I had to do that change to pom.xml, before I got it to compile.
That is, I did:
mvn hpi:create
entered groupId foo.hyde.jenkins.plugins, artifactId hello-world when prompted.
cd hello-world
mvn install failed
Edit pom.xml to change the parent
mvn install succeeded
mvn hpi:run -Djetty.port=8092 succeeded (Using that port because other Jenkins is already in default port, otherwise -D... not needed.)
Go to http://localhost:8092, check global config, create job and add the build step
And it worked for me.
I'm using Maven 2, version 2.2.1.
I finally find the answer to my questions. The problem is that I was using an old version of maven, the 2.2.1 version. So I change to the last version, 3.0.4, everything is fine now.

org.apache.maven.BuildFailureException: No SCM URL was provided to perform the release from

I'm using Maven 2.2.1 and I sucessfully ran:
mvn -B release:clean release:prepare
But get the error message:
No SCM URL was provided to perform the release from
when I run:
mvn release:perform
My pom.xml have the scm tags defined correctly:
<scm>
<url>file:///C:/tmp/svnrepo/myproj/trunk</url>
<connection>scm:svn:file:///C:/tmp/svnrepo/myproj/trunk</connection>
<developerConnection>scm:svn:file:///C:/tmp/svnrepo/myproj/trunk</developerConnection>
</scm>
It is possible to rerun a maven release:perform by creating a manually edited release.properties file in the root folder. This file should define these two properties: scm.url and scm.tag. Here a possible example:
scm.url=scm:git:https://github.com/owner/repo.git
scm.tag=v1.0.4
With this file it is possible to redo a release:perform task.
Inspired by this answer.
Looks like I did a mvn -DdryRun=true release:perform and this had deleted the release.properties file from the prepare stage.
So I add the -DconnectionUrl to the command to provide url of the tag
It should work. I had similar problem, but in my case perform failed due to network error and I had to restart it with something like:
mvn release:perform -rf :{ARTIFACT ON WHICH IT FAILED} -DconnectionUrl=scm:svn:{URL TO TAG}
The message
No SCM URL was provided to perform the release from
does not mean the SCM URL in the pom.xml!
There are two kinds of SCM-URLS:
Trunk Folder (for development)
Tag Folder (for tagging the release)
In the pom.xml you specify the trunk-folder-url. What the release:perform require is the tag-folder-url. You can specify the parameter -DconnectionUrl.
Usually you are using prepare and perform in one maven call. Prepare do all preparation stuff and will commit some resources to the version-control-system using the comment [maven-release-plugin] prepare release XXX- BUT NOT ALL FILES ARE COMMITTED! One important file is not committed to the version-control-system, the release.properties. This file is used if you omit the -DconnectionUrl.
The problem occourse while perform because the checkout/commit require the release.properties or the -DconnectionUrl respectivly.
You can either:
Specify the tag-url by using -DconnectionUrl or
Call release:prepare release:perform in one shot to rely on the not-committed release.properties
More informations are here
I got this same exception in our CI automation and it turned out to be due to the fact that target/checkout directory already has a release build. For one of the projects, we had to introduce an improvised maven release perform build between the real maven release:prepare and release:perform steps. As part of improvisation the release tag is checked out to target/checkout and what I noticed is that if this directory is left undeleted, it would cause the release:perform to fail with the No SCM URL was provided to perform the release from error. I don't know if it matters, but we also use -DlocalCheckout=true option.
Simply running mvn release:clean release:prepare first, and then mvn release:perform worked for me.

Maven Release Plugin - Multi-module project skipping modules

I am using maven-release-plugin on a multi-module project with the following layout:
ROOT/
+ parent
+ module1
+ module2
In the parent's pom, the child modules configured using modules element. Each one of the projects are configured to use the plugin with basic configuration and a tag base for each. I have the following problems:
When I run mvn release:prepare on parent, after the line that says Checking for snapshot dependencies ..., I receive no prompt to enter the versions. If I press Enter for the number of questions it requires answer, it continues. Why do not I receive prompts on the screen? (The same thing happens if run with -DdryRun=true)
After running mvn release:prepare (with or without -DdryRun=true), the release:prepare is SKIPPED for the child modules.
I am using the basic configuration on the plugin's guide. I'd be thankful for any ideas or clues of what's wrong.
Regarding the lack of prompts, are you running mvn through a pipe? This happened to me when I was using a script to do colour highlighting of Maven's log output, because Maven doesn't output a newline after the prompt.
By the way, you may be able to use mvn's -B option to run in batch mode; maven-release-plugin will use the default values instead of prompting.

Resources