This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes comand line arguments in pom Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "comand line arguments in pom " Watch "comand line arguments in pom " New topic
Author

comand line arguments in pom

Jina Lu
Greenhorn

Joined: Jul 09, 2010
Posts: 25

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

Joined: Jun 25, 2001
Posts: 15950
    
  19

It depends on where in the POM you employ them.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jina Lu
Greenhorn

Joined: Jul 09, 2010
Posts: 25

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

Joined: May 14, 2008
Posts: 5812
    
    7

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.)


JBoss In Action
Jina Lu
Greenhorn

Joined: Jul 09, 2010
Posts: 25

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

Joined: May 14, 2008
Posts: 5812
    
    7

Sounds to me like you want to use the effective POM. You can generate that using the Help plugin.
Jina Lu
Greenhorn

Joined: Jul 09, 2010
Posts: 25

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

Joined: May 14, 2008
Posts: 5812
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: comand line arguments in pom
 
Similar Threads
Publish to maven repository as "latest"
Install 3rd party jars
How to avoid using systemPath and make maven read jars from /lib
how to make the plugin jar to take the specified version from the pom.
Running help:describe command in Maven