简体   繁体   English

依赖管理和依赖版本的问题

[英]Problem with dependencyManagement and dependency versions

I have problem with relations of pom, with dependency versions etc. Below my structure: My MAIN pom, which gives me the order to build of all projects我对 pom 的关系、依赖版本等有问题。在我的结构下面:我的 MAIN pom,它给了我构建所有项目的命令

  <groupId>com.xyz</groupId>
  <artifactId>yxz</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>xyz</name>

  <modules>
    <module>commons</module>
    <module>projectA</module>
    <module>ProjectB</module>
    ...
    <module>ProjectX</module>
  </modules>

COMMONS pom, it is designed to have common dependencies and properties, without any parent COMMONS pom,它被设计成有共同的依赖和属性,没有任何父

<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>

<name>commons</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.version>3.8.1</maven.compiler.version>
    <java.version>11</java.version>
    <lombok.version>1.18.24</lombok.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

ProjectA pom, include commons dependency, with spring-boot in parent, ProjectA pom,包括公共依赖,父级为 spring-boot,

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.xyz</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectA</name>

<properties>
    <java.version>11</java.version>
    <spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.xyz</groupId>
        <artifactId>commons</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    ...
    <dependency>
        some dependencies from org.springframework.cloud
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    ...
</build>

ProjectB pom, include commons dependency, with custom framework in parent, ProjectB pom,包括公共依赖项,在父项中具有自定义框架,

<parent>
    <groupId>com.customframework</groupId>
    <artifactId>custom.framework</artifactId>
    <version>1.8.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>com.xyz</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectB</name>

<properties>
    <java.version>11</java.version>
    <customeframework.feign.version>10.12</customeframework.feign.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.xyz</groupId>
        <artifactId>commons</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    ...
    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-core</artifactId>
        <version>11.8</version>
    </dependency>
        other feign dependecies with 11.8 version
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.customframework</groupId>
            <artifactId>custom.framework.feign</artifactId>
            <version>${customeframework.feign.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    ...
</build>

When i build my all projects then:当我构建我的所有项目时:

  • projectA has lombok with version from springframework.cloud dependency management, not with version from commons projectA 的 lombok 版本来自 springframework.cloud 依赖管理,而不是来自 commons 的版本
  • ProjectB has similar problem with feign, if i add feign dependency with version 11.8, maven use version from customframework (version 9.x) ProjectB 与 feign 有类似的问题,如果我添加 11.8 版本的 feign 依赖项,maven 使用来自 customframework 的版本(版本 9.x)

What i want to do:我想做的事:

  • I tried add bom pom file, like next module to MAIN pom but how should i add it when i have other dependency management from springframework.cloud我尝试将 bom pom 文件添加到 MAIN pom 中,例如下一个模块,但是当我有来自 springframework.cloud 的其他依赖项管理时,我应该如何添加它
  • i have 5-6 projects with spring boot parent, some with quarqus and with custom framework and i want configure all dependency versions and parent spring boot versions in one file我有 5-6 个带有 spring 引导父级的项目,一些带有 quarqus 和自定义框架,我想在一个文件中配置所有依赖版本和父级 spring 引导版本

If you want to have the same dependencies in all modules then how about you define <dependencyManagement> with all required BOMs and versions in one place (eg in commons module)?如果您想在所有模块中具有相同的依赖关系,那么您如何在一个地方(例如在 commons 模块中)定义具有所有必需 BOM 和版本的<dependencyManagement>

It won't bother the modules if they don't include some of the dependencies but it will make sure that all the modules have the same dependencyManagement rules.如果它们不包含某些依赖项,它不会打扰模块,但它会确保所有模块都具有相同的dependencyManagement 规则。

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

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