Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven update dependencies in POM

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> 
like image 856
javamonkey79 Avatar asked Jun 09 '09 23:06

javamonkey79


4 Answers

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

like image 86
Dominic Mitchell Avatar answered Nov 11 '22 02:11

Dominic Mitchell


I prefer using mvn versions:display-dependency-updates; this generates a report of which dependencies can be upgraded, but lets you modify the POMs yourself. There's also a display-plugin-updates command for plugins.

like image 35
piepera Avatar answered Nov 11 '22 01:11

piepera


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

like image 6
rperez Avatar answered Nov 11 '22 01:11

rperez


Personally, I think there should be an additional parameter in maven that would allow you to add to the pom.xml.

See post at http://maven.40175.n5.nabble.com/Is-there-any-maven-plugin-to-add-dependency-to-existing-pom-xml-td2839092.html#a5772853

Here, you can add the following to your pom.xml file:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.1</version>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

...

Then backup your pom.xml file via version set command:

mvn versions:set -DnewVersion=9.9.9

Run latest versions:

mvn versions:use-latest-versions

and diff the pom.xml files, pom.xml and pom.xml.versionsBackup

like image 3
Scott Izu Avatar answered Nov 11 '22 02:11

Scott Izu