views:

2516

answers:

3

Are there any preexisting Maven plugins or commands to update the dependencies in the POM? Example: (if this was in my POM)

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.3</version>
</dependency>

Is there a command or plugin I can run to get it to update the dependency to:

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.4</version>
</dependency>

Thanks in advance.

+2  A: 

No there is isn't. And be happy there is not. How would such a tool know how to upgrade your dependencies?

With breakages possibly happening between minor versions, it would be a disaster waiting to happen.


But you can always write your own Mojo for that.

  • get latest version of dependency from Maven repository
  • compare with version from pom.xml
  • rewrite pom.xml
  • run mvn test
  • ?
  • Profit!
Robert Munteanu
I kinda figured that is what it would come down to - I've been looking for a Mojo project to do anyways, thanks.
javamonkey79
That's always a good thing to hear. Be sure to post a link if you decide to go the open source way.
Robert Munteanu
This may have been true once, but is no longer (@Robert: suggest you refine your answer?).
Andrew Aylett
@Andrew: the accepted answer is correct, so I'm not going to just copy that. I still feel that it would be quite fun to create such a harness.
Robert Munteanu
+1  A: 

you can use dependencyManagement in your parent pom:

<dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>commons-lang</groupId>
              <artifactId>commons-lang</artifactId>
              <version>2.4</version>
          </dependency>
      </dependencies>
</dependencyManagement>

this way, you need to change the version only once in the parent POM

rperez
this is much preferred to having some tool update stuff in ways that you may or may not control. You also guarantee that all children will be using the version specified.
Mike Pone
+9  A: 

Try the maven-versions-plugin, in particular, the versions:use-latest-versions goal.

Dominic Mitchell
This does what the poster requested, although I think use-latest-releases is better in most cases. But this is definitely the plugin to use.
Zac Thompson
Dang, now that I already built it! I guess as the saying goes, "don't reinvent wheels unless you want to learn alot about wheels". :)Thanks!
javamonkey79
Yup — I missed use-latest-releases. Thanks, Zac.
Dominic Mitchell