maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Wood <>
Subject Way to reload the pom.xml model?
Date Mon, 25 Jan 2010 17:50:29 GMT
Hey everyone,

I've written a maven-plugin with a bunch of mojo's to aid in my
employer's release process of our software.

It's executed in a manner such as this:

mvn dependency-resolver:resolvesnapshots release:prepare
release:perform dependency-resolver:writeversion

Essentially the first goal replaces SNAPSHOT dependencies with
concrete versions, in an automated fashion (it maintains a release
manifest-style file in SCM).

For reasons beyond my control, I need to preserve the state of the
project-to-be-released's pom.xml file (in SCM, except for the
dependency section), so instead of simply iterating through the
project/model dependencies like this:

List deps = mavenProject.getDependencies();

for( Iterator it = deps.iterator(); it.hasNext();){
    Dependency dependency = (Dependency);

    //code to determine newVersion



and then calling

mavenProject.writeModel(...); this results in the pom.xml file looking quite different from
the original (which is bad for a few reasons, svn commits will be
ugly, management reasons, etc). So, instead of calling
MavenProject.writeModel() and then checking the file into SCM, I wrote
some dom/xpath code to the modify the pom.xml (dependency section)
file itself. I then check the changes into SCM.

The problem with this is when the next goal (release:prepare)
executes, it doesn't see the changes to the pom.xml file's dependency
section, and dies because it can't resolve the SNAPSHOT deps. So, then
I'm forced to resolve the dependencies in the project's model as above
(only up to the MavenProject.setDependencies(...) method, to preserve
the xml) as well as the dom/xpath/SCM checkin steps.

The plugin now works fine the way it is, but I'm weirded out because
I'm effectively doing the same thing twice, which always smells bad to

So, my question: Is there a way to force a mojo to reload the project
from its pom.xml file, so if there are interim changes to the pom, it
reloads the model?


Oh, I realize this could be avoided by executing the goals
individually (ex. mvn dependency-resolver:resolvesnapshots ; mvn
release:prepare ; et c) and not all in the same command, but I don't
want to do that.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message