This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comand line arguments in pom

 
Jina Lu
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using command line arguments to specify some pom parameters like <version>1.0-${date}</version> and maven command would be "mvn clean install -Ddate=1".
The problem is that when I check my local maven repository I still notice ${date} in the pom. Building using maven 2.
Is it normal that command line variables are not resolved?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18167
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on where in the POM you employ them.
 
Jina Lu
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for answer Tim, but could you explain what you mean by saying:

Tim Holloway wrote:It depends on where in the POM you employ them.

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the correct behavior - the exact POM you used to do the build gets loaded into the repository without ANY changes. If you want a POM that contains replaced property values to be placed into the repository, you might use a plugin such as Version plug (http://mojo.codehaus.org/versions-maven-plugin/) which replaces the POM with one that has some data filled in. (Note that you then have to be careful not to check in this updated POM into the version control system.)
 
Jina Lu
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter, I'm considering using maven plugin which would replace all properties in pom to ones I specify in command line.
Maybe you could recommend one that would replace all, not only version? The most important are artifactId and version.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds to me like you want to use the effective POM. You can generate that using the Help plugin.
 
Jina Lu
Greenhorn
Posts: 26
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes effective pom is quite similar to result I want. Howether I need only the artifactId and version to be set, to have project correctly deployed in the repository.
Any ideas or it is impossible for maven and I should update the original pom before running mvn deploy command?
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to understand how Maven uses the POM. It has a "Super" POM which defines a lot of defaults which it loads into a internal object model. It loads your POM on top of that. When the Help plugin generates the effective POM, essentially it reads the object model and creates a POM based on that. But what you want if the POM to be read as a text file with certain properties filtered. The only two options are I think of is to use the Versions plugin (which I already mentioned) or the Resources plugin (have it copy the POM filtering the properties), but even that will filter more than what you want. The only other option is to write your own plugin to do this (that's what we did, it's not that hard and you end up learning a lot about how Maven works in the process).

By the way, I haven't mentioned this yet, but placing properties in <version> will cause Maven 3.0.x to complain - a future version of Maven could disallow doing this. Our plugin gets around this by using a keyword within the version string (just like you can use the keyword SNAPSHOT), then Maven is happy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic