0

I am using Maven 3.3.3. I just upgraded from 3.1.1 and noticed that I can't pass in a version anymore.

pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.hello.world</groupId>
<artifactId>helloworld</artifactId>
<version>${VERSION_NUMBER}</version>
<packaging>pom</packaging>
<properties>
    <VERSION_NUMBER>LOCAL-ONLY-SNAPSHOT</VERSION_NUMBER>
</properties>

mvn package -DVERSION_NUMBER=1.2.3

After upgrading to Maven 3.3.3, I now get the error message: [ERROR] Version must be a constant

My goal is to be able to pass in a version number and never have actual numbers in the pom.xml. I don't want to use the versions-plugin, as that actually changes the pom.xml to use a specific version number. No version numbers in source control.

sworded
  • 2,419
  • 4
  • 31
  • 48
  • See this it may help you http://stackoverflow.com/questions/1981151/warning-on-using-project-parent-version-as-the-version-of-a-module-in-maven-3 – Subodh Joshi Aug 21 '15 at 13:55
  • @SubodhJoshi That link still doesn't have an answer relevant to my question. I still need to figure out how do I use ${buildNumber} from buildnumber-maven-plugin in version? – sworded Aug 21 '15 at 19:22
  • I have my doubts that you have updated from a Maven version 3.1.3? Does not exist.... – khmarbaise Aug 23 '15 at 11:20

2 Answers2

0

You have to use one or a combination of the following properties:

${revision}, ${changelist}, and ${sha1}. 

That's simply the reason it does not work.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Could you explain how this works? I replaced VERSION_NUMBER with revision, and I get the same error - version must be a constant. – sworded Aug 24 '15 at 17:18
0

Unfortunately, it is not possible to do what you're attempting in the latest versions of maven - the version is so integral to the build process that you must specify it explicitly in your POM.

The only way around it (and I'm not suggesting that this is a good idea) would be to add a pre-processing step before your maven command e.g. using sed to modify the POM and set whatever version number you want.

Just out of curiosity, why do you want to do this?

olambert
  • 1,075
  • 2
  • 7
  • 10
  • I'd like to get my CI server (Jenkins) to manage all versioning and releasing, without having any developers worry. – sworded Aug 25 '15 at 16:59