Java 使用BOM表时存在可传递依赖关系问题

Java 使用BOM表时存在可传递依赖关系问题,java,maven,maven-2,maven-3,maven-bom,Java,Maven,Maven 2,Maven 3,Maven Bom,假设我有 1.bom项目(命名为bom) 2.jar项目(命名为a) 3.战争项目(命名为B) bom项目的jackson数据版本为属性中的2.8.5和2.8.1,以及jackson数据的从属管理第2.8.5节。 继承bom表的项目A在版本2.8.1中声明了其中的数据依赖关系 项目B依赖于项目A并继承bom表。它不在其依赖项中声明jackson数据 现在,当我查看项目B的lib dir时,jackson数据版本是2.8.5,其中项目A将其声明为2.8.1 无论依赖关系中声明了什么,它都采用bom

假设我有
1.bom项目(命名为bom)
2.jar项目(命名为a)
3.战争项目(命名为B)

bom项目的jackson数据版本为属性中的2.8.5和2.8.1,以及jackson数据的从属管理第2.8.5节。

继承bom表的项目A在版本2.8.1中声明了其中的数据依赖关系

项目B依赖于项目A并继承bom表。它不在其依赖项中声明jackson数据

现在,当我查看项目B的lib dir时,jackson数据版本是2.8.5,其中项目A将其声明为2.8.1

无论依赖关系中声明了什么,它都采用bom中声明的版本。有没有办法解决项目B中jackson数据的可传递依赖性,因为项目A中声明的数据在使用bom时是指2.8.1而不是2.8.5的版本

以下是POM


BOM项目


4.0.0
com.test
物料清单
1.1
聚甲醛
2.8.5
2.8.1
com.test
A.
1
com.fasterxml.jackson.core
杰克逊数据绑定
${jackson databind.version}

项目A的pom

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>bom</artifactId>
        <version>1.1</version>
    </parent>
    <groupId>com.test</groupId>
    <artifactId>A</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.1</version>
        </dependency>

    </dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.emirates.ibe</groupId>
    <artifactId>bom</artifactId>
    <version>1.1</version>
</parent>
    <groupId>com.test</groupId>
    <artifactId>B</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <dependencies>

        <dependency>
            <groupId>com.test</groupId>
            <artifactId>A</artifactId>
        </dependency>

    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warName>B</warName>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
com.test
物料清单
1.1
com.test
A.
1
com.fasterxml.jackson.core
杰克逊数据绑定
2.8.1

项目B

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.test</groupId>
        <artifactId>bom</artifactId>
        <version>1.1</version>
    </parent>
    <groupId>com.test</groupId>
    <artifactId>A</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.1</version>
        </dependency>

    </dependencies>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<parent>
    <groupId>com.emirates.ibe</groupId>
    <artifactId>bom</artifactId>
    <version>1.1</version>
</parent>
    <groupId>com.test</groupId>
    <artifactId>B</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <dependencies>

        <dependency>
            <groupId>com.test</groupId>
            <artifactId>A</artifactId>
        </dependency>

    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <warName>B</warName>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

4.0.0
com.emirates.ibe
物料清单
1.1
com.test
B
1
战争
com.test
A.
src
maven编译器插件
3.1
1.7
1.7
maven战争插件
2.6
B
网络内容

依赖项管理覆盖可传递依赖项。这就是这里发生的事情(这就是它的本意)


如果您想要一个不同的版本,可以更改DependencyManager,或者在使用

的项目中重写。了解这就是maven的实现方式。但是还有其他方法来重写此功能吗?我提供了两种方法。您不喜欢它们的哪些方面?我们正在将一个大型的整体式应用程序分离为小型的独立项目(目前有200多个项目)。它们都有一个共同的bom表。所有这些项目都是相互依存的(现在我们通过nexus解决)。由于它是一个遗留应用程序,不同的项目使用相同的第三方libs的不同版本,它们工作得很好
现在如果将dependencyManagement更改为,即我强制项目使用第三方应用程序的相同版本(他们可能会失败)。如果我们要覆盖pom,我必须检查所有可传递的DEP并修改pom。因此,我正在寻找一种方法,使我能够覆盖maven的默认行为,并且可传递的依赖项不会被bom覆盖。这将确保我们不会违反现有规范,同时我们将项目作为第一阶段的一部分进行隔离。您的答案非常适合我们的第二阶段计划,我们将强制开发人员根据需要在其项目中使用相同的版本或覆盖这是不可能的。如果不希望dependencyManagement就位,则需要从
com.test:bom
父POM中删除它。您的父POM本质上是说:“覆盖可传递版本”,因此如果您不希望这样,请将其从父POM中删除。