代码之家  ›  专栏  ›  技术社区  ›  Vincent F

maven版本在哪里被重写?

  •  0
  • Vincent F  · 技术社区  · 6 年前

    我正在构建一个springbootstarter,遵循推荐的core/autoconfigure/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

    在我的根里pom.xml文件,我这样声明物料清单:

    <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>
    

    <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>
    

    现在,在另一个项目中,我使用starter。所以我的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
    

    如果我在pom.xml文件,在启动程序之前声明gson 2.8.5,那么它就工作了。。

    但在Maven的工作方式中,我肯定遗漏了一些东西。。

    如果您想在本地尝试,此分支中提供代码: https://github.com/societe-generale/github-crawler/tree/sprinBoot2upgrade

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

    谢谢!

    编辑1

    正如评论中提到的,springbootstarter将gson版本改写为2.8.5(而不是在feigncore中计划的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

    1 回复  |  直到 6 年前
        1
  •  0
  •   Vincent F    6 年前

    根据问题评论中的各种提示进行快速总结

    详细模式为 discontinued since Maven 3.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