Maven POM version management for multiple maven pr

2019-08-02 04:51发布

问题:

In our projects, we have about 25 maven projects and each one of them contains at least 3 module projects and one parent POM. So total is around (25 *4) 100 POM files. Is there any easy way to maintain POM change version ? So this task become tedious and boring task. This must be common problem across the Software Development ?

Does anyone have scripts or tool to do this version change to handle following 3 cases ?

1)  
    <dependency>
      <groupId>THEGROUPID</groupId>
      <artifactId>THEARTIFACT</artifactId>
      <version>THE-VERSION</version>
    </dependency>

2)
    <dependency>
      <groupId>THEGROUPID</groupId>
      <artifactId>THEARTIFACT</artifactId>
      <version>$(version.number)</version>
    </dependency>
3)
  <parent>
    <groupId>THEGROUPID</groupId>
    <artifactId>THEARTIFACT</artifactId>
    <version>THE-VERSION</version>
  </parent>

We have 25 maven projects and each one have on each other (via parent pom but not cyclic dependency) dependency, between them. So When we change a version of one of the lib, it needs to be changed throughout out all the maven module parent POMs..... Hence, I was looking for tool that can achieve this across the rage of POMs not just one muti-module project (release plug-in will only release and ONE maven muti-module project.) I hope this will have better understanding of the problem..

Basically, I am looking for linux SED type of command but for specific groupid and artifactid.

Thanks,

Bmis13

回答1:

Put all the versions in the <dependencyManagement> in your parent pom:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>THEGROUPID</groupId>
      <artifactId>THEARTIFACT</artifactId>
      <version>THE-VERSION</version>
    </dependency>
  </dependencies>
</dependencyManagement>

Hereby, you do not need to add the <version> tag to your child poms.

Ref: dependencyManagement (scroll down)



回答2:

Use versions-maven-plugin with its set mojo:

cd <your-super-parent-pom>
mvn versions:set -DoldVersion=1-SNAPSHOT -DnewVersion=2-SNAPSHOT

This plugin however has some limitations. It does not cope with certain (complex) structures where pom inheritance is complex, and I am also not sure if it handles property references.

There is similar functionality inside maven-release-plugin. It might have a slightly higher chance to work better, as it is used more frequently - and AFAIK the code is not shared - but I have no direct experience with this. I just observed many releases with correct version renumbering in quite difficult scenarios...



回答3:

I wrote my own tool to do this. It's called 'pommel' and you can get it here:

http://code.google.com/p/pommel/

You define a mapping file and run it from the command line i.e.

java -jar pommel-1.0.0.jar -iC:\Development\java\projects -mmapping.xml

The mapping file takes the form:

<?xml version="1.0"?>
<mappings>
  <mapping>
    <dependency-source>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>*</version>
    </dependency-source>
    <dependency-target>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.9</version>
        <scope>test</scope>
    </dependency-target>
  </mapping>

</mappings>

This will replace all references to junit with the specified dependency target. Not you can use a wild card in the dependency source definition. It will apply the mapping to ALL pom files it find under the specified directory.



标签: maven pom.xml