maven版本在哪里被覆盖?

问题描述 投票:0回答:1

我正在按照建议的约定使用core / autoconfigure / starter模块分离来构建一个spring boot starter。当我查看maven依赖树时,这就是我所拥有的:

[INFO] com.myDomain.myProject:myProject-starter:jar:1.0.8-SNAPSHOT
[INFO] +- com.myDomain.myProject:myProject-autoconfigure:jar:1.0.8-SNAPSHOT:compile
[INFO] |  \- com.myDomain.myProject:myProject-core:jar:1.0.8-SNAPSHOT:compile
[INFO] |     +- io.github.openfeign:feign-gson:jar:9.5.1:compile
[INFO] |     |  +- io.github.openfeign:feign-core:jar:9.5.1:compile
[INFO] |     |  \- com.google.code.gson:gson:jar:2.8.5:compile

gson来自v2.8.5,这是我期望的版本 - 我的项目与它一起工作

(注意:在https://mvnrepository.com/artifact/io.github.openfeign/feign-core/9.5.1中,我们看到gson的预期版本是2.5 ......所以不确定为什么我得到2.8.5 ..)

在我的root pom.xml中,我声明了这样的BOM:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-openfeign-dependencies</artifactId>
            <version>2.0.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

在我的“核心”pom.xml中:

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-gson</artifactId>
    </dependency>

    <dependency>
        <groupId>io.github.openfeign</groupId>
        <artifactId>feign-httpclient</artifactId>
    </dependency>
</dependencies>

现在,在另一个项目中,我使用了启动器。所以我的pom.xml非常简单:

<dependencies>
    <dependency>
        <groupId>com.myDomain.myProject</groupId>
        <artifactId>myProject-starter</artifactId>
        <version>1.0.8-SNAPSHOT</version>
    </dependency>
</dependencies>

当我查看这个项目中的依赖树时,我得到了这个:

[INFO] \- com.myDomain.myProject:myProject-starter:jar:1.0.8-SNAPSHOT:compile
[INFO]    +- com.myDomain.myProject:myProject-autoconfigure:jar:1.0.8-SNAPSHOT:compile
[INFO]    |  \- com.myDomain.myProject:myProject-core:jar:1.0.8-SNAPSHOT:compile
[INFO]    |     +- io.github.openfeign:feign-gson:jar:9.5.1:compile
[INFO]    |     |  +- io.github.openfeign:feign-core:jar:9.5.1:compile
[INFO]    |     |  \- com.google.code.gson:gson:jar:2.5:compile

gson来自v2.5,因此它不起作用。如果我在pom.xml中覆盖它,通过在启动器之前声明gson 2.8.5,那么它可以工作..

但是必须有一些我在Maven工作的方式中缺少的东西。

我已经尝试从我的本地仓库中删除1.0.8快照版本,然后重建它,以确保我的第二个项目没有使用旧版本,但我在构建中不断获得这个不正确的版本,我没有线索它来自哪个/什么覆盖它。

如果你想在本地试一试,可以在这个分支中找到代码:https://github.com/societe-generale/github-crawler/tree/sprinBoot2upgrade

我真的对任何调查指针感兴趣,了解根本原因,因为我现在很困惑..

谢谢 !

=========================================

编辑1

正如评论中所提到的,它是Spring Boot启动程序,它将gson版本覆盖到2.8.5(而不是在feign-core中计划的2.5)。

所以现在问题变成了:当我在没有父项的另一个项目中使用starter作为单一依赖项时,如果被覆盖的版本(2.8.5)消失,我最终得到的初始版本(2.5)与之不兼容spring-boot-autoconfigure 2.0.4.RELEASE?

编辑2

我在这里创造了一个新的,更有针对性的问题:Not getting the expected version when using the Spring Boot starter I built

maven spring-boot maven-3 spring-cloud spring-cloud-feign
1个回答
0
投票

基于问题评论中的各种提示的快速摘要

详细模式是discontinued since Maven 3.x,所以使用mvn依赖:tree -X来获取有关使用/覆盖的版本等的更多细节。然后你得到类似的东西:

[DEBUG] io.github.openfeign:feign-gson:jar:9.5.1:compile 
[DEBUG]    com.google.code.gson:gson:jar:2.8.5:compile (version managed from 2.5 by org.springframework.boot:spring-boot-dependencies:2.0.4.RELEASE)

- >这清楚地指出了版本的来源,即https://github.com/spring-projects/spring-boot/blob/v2.0.4.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml#L65

© www.soinside.com 2019 - 2024. All rights reserved.