How to auto-update versions only for dependencies within multi-module/reactor build?

回眸只為那壹抹淺笑 提交于 2019-12-11 04:15:19

问题


When I run the following command for the root project, it checks for updates of ALL dependencies:

mvn versions:use-latest-versions

I want to limit versions update for only those dependencies which are reachable from the root:

root/pom.xml
├── A/pom.xml
│   └── D/pom.xml
│       └── E/pom.xml
├── B/pom.xml
└── C/pom.xml
    ├── F/pom.xml
    └── G/pom.xml

The group and artifact ids of these dependencies are in the current reactor build (multi-module build).

For example, I don not want to update external dependencies like junit or commons-logging.

There is an option excludeReactor. And I need an opposite like includeOnlyReactor.

Otherwise, it is unreliable and tedious work to specify all possible artifact patterns "owned" by your project via includes option.


回答1:


Set module dependencies version to ${project.version} Good practice is to do it in dependencyMnaagement section of root pom.

Example:

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>


<modules>
    <module>A</module>
    <module>B</module>
    <module>C</module>
</modules


<dependencyManagement>
    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>A</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>B</artifactId>
        <version>${project.version}</version>
    </dependency>

    ...And so on....

    <dependency>
        <groupId>com.mycompany.app</groupId>
        <artifactId>G</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencyManagement>


</project>  

Then whenever you want to use the module in another module (e.g. module G in B) you put just

<dependency>
    <groupId>com.mycompany.app</groupId>
    <artifactId>B</artifactId>
</dependency>

To change version of the project use mvn versions:set. This will keep all the modules in the same version and the dependency management section will keep the dependencies in the same version as well.

Obviously it won't work if you want to keep your modules in same version all the time. But this will be more tricky anyway.



来源:https://stackoverflow.com/questions/31579730/how-to-auto-update-versions-only-for-dependencies-within-multi-module-reactor-bu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!