简体   繁体   English

检查多模块 Maven 项目中的依赖版本

[英]Check dependency version in a multi-module Maven project

I have this dependencyManagement in my parent POM of my multi-module project:我的多模块项目的父 POM 中有这个 dependencyManagement:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>A</artifactId>
            <version>3.5</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>B</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>C</artifactId>
            <version>1.1</version>
        </dependency>
</dependencyManagement>

And this in every child module POM:这在每个子模块 POM 中:

Module A:模块 A:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>A</artifactId>
<version>3.5</version>
<packaging>nbm</packaging>

Module B:模块 B:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>B</artifactId>
<version>1.0</version>
<packaging>nbm</packaging>

Module C:模块 C:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>C</artifactId>
<version>1.1</version>
<packaging>nbm</packaging>

Every time that we want to release, we have to check that the version in every child module is the same that the version in the dependencyManagement (developers are asked to change the version in both places every time they change something).每次我们要发布时,我们必须检查每个子模块中的版本是否与dependencyManagement 中的版本相同(开发人员在每次更改时都被要求更改两个地方的版本)。

There is some way to check that the versions are the same automaticaly?有什么方法可以自动检查版本是否相同? If the versions are not the same, how could I change them automaticaly?如果版本不一样,我怎么能自动更改它们?

Parent pom discovery-ui :父 pom 发现-ui:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>discovery-ui</artifactId>
    <version>1.0</version>
</parent>

<properties>
        <A.version>3.5</A.version>
        <B.version>1.0</B.version>
        <C.version>1.1</C.version>
<properties>
        
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>A</artifactId>
            <version>${A.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>B</artifactId>
            <version>${B.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>C</artifactId>
            <version>${C.version}</version>
        </dependency>
</dependencyManagement>

Module A:模块 A:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>discovery-ui</artifactId>
    <version>1.0</version>
</parent>
<artifactId>A</artifactId>
<version>${A.version}</version>
<packaging>nbm</packaging>

Have you tried maven versions plugin ?您是否尝试过Maven 版本插件 Looks like processParent parameter should do the trick.看起来processParent参数应该可以解决问题。 I have not tested it yet, though.不过,我还没有测试过。

mvn versions:set -DgenerateBackupPoms=false -f A/pom.xml -DnewVersion=NEW_VERSION -DartifactId=A -DprocessParent=true

You already have declared dependencies and their versions in your parent POM under the <dependencyManagement> section.您已经在<dependencyManagement>部分下的父 POM 中声明了依赖项及其版本。 This way you need only to declare GroupID:ArtifactID in your child POM (without version, it will be inherited from the parent POM)这样你只需要在你的子 POM 中声明 GroupID:ArtifactID (没有版本,它将从父 POM 继承)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM