3
votes

I am trying to use the maven-release-plugin with some environment variables, but I get an issue when I use an environment variable for the release version.
I am executing:

mvn release:clean --batch-mode -Dtag=${env.tag} -Dproject.rel.com.mycompany.project:project-root=${env.project.rel.com.mycompany.project:project-root} -Dproject.dev.com.mycompany.project:project-root=${env.project.dev.com.mycompany.project:project-root} release:prepare

I am getting:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.4:prepare (default-cli) on project project-root: Error parsing version, cannot determine next version: Unable to parse the version string: "${env.project.rel.com.mycompany.project:project-root}" -> [Help 1]

If I change the ${env.project.rel.com.mycompany.project:project-root} to a specific version, the command will pass.

But as you can see I am using:

${env.tag}  
${env.project.dev.com.mycompany.project:project-root}  

with no issues. Is this a bug? Or am I doing something wrong?

Additional notes:

Environment variables:

tag=2.55  
project.rel.com.mycompany.project:project-root=2.55  
project.dev.com.mycompany.project:project-root=2.56-SNAPSHOT  

My Maven version is:

C:\>mvn -version  
C:\>set MAVEN_OPTS=-Xmx1024m -XX:MaxPermSize=512m  
Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)  
Maven home: C:\Users\John\Documents\apache-maven-3.0.4-bin  
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.  
Java home: C:\JDK\jdk1.6.0_25\jre  
Default locale: en_US, platform encoding: Cp1252  
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"  
2

2 Answers

6
votes

you will have to use the arguments attribute: http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#arguments

So in your context your cmd line will look like this (Note the double quotes as well):

mvn release:clean --batch-mode release:prepare "-Darguments=-Dtag=${env.tag} -Dproject.rel.com.mycompany.project:project-root=${env.project.rel.com.mycompany.project:project-root} -Dproject.dev.com.mycompany.project:project-root=${env.project.dev.com.mycompany.project:project-root}"

Furthermore, if i remember right the uses of the tokens ${env.X} requires the usage of the property name in upper case (to be verified)

0
votes

It's not working because the release plugin clears the environment[1]. I doubt it's documented[2], I found out by looking at the source. Farid's answer is a good workaround - it passes the environment value via java properties which are not cleared.

I would have simply commented on Farid's answer but SO doesn't think I'm shiny enough.

  1. Why??
  2. Classic maven.