【问题标题】:Why are properties from spring-boot-dependencies not available in child POM?为什么子 POM 中没有来自 spring-boot-dependencies 的属性?
【发布时间】:2018-04-09 15:22:32
【问题描述】:

我正在关注 Spring 文档 Using Spring Boot without the parent POM。在我的父 POM 中,我在 dependenciesManagement 部分中定义了对 spring-boot-dependencies 的导入依赖项。然后在我的子 POM 中定义对 spring-boot-starter-jersey 的依赖,而不是指定任何版本。当我查看dependency:tree 时,我看到所有球衣依赖项都使用spring-boot-dependencies 中指定的版本。一切都很好。

现在,在我的子 POM 中,我需要添加另一个球衣依赖项。在spring-boot-dependencies POM 中,我看到定义了一个属性jersey.version。但是,当我在我的子 POM 中使用 ${jersey.version} 时,没有定义该属性。

为什么${jersey.version} 在子 POM 中不可用?

父 POM sn-p:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

子 POM sn-p:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-sse</artifactId>
        <version>${jersey.version}</version>  <!-- error here -->
    </dependency>
</dependencies>

来自spring-boot-dependencies-1.5.0.RELEASE.pom

<properties>
    <jersey.version>2.25.1</jersey.version>
</properties>

【问题讨论】:

  • 如果在 spring-boot-dependencies docs.spring.io/spring-boot/docs/current/reference/html/…987654322@ 中使用 dep,则不需要提供版本
  • @Georgy:我需要添加一个不在spring boot依赖项中的附加依赖项,并且想在spring boot依赖项中使用与相关工件相同的版本。
  • 好的,我明白了,因为不在 spring-boot-dependencies maven 中的依赖 jersey-media-sse 无法解析版本,所以它适用于 spring-boot-dependencies 中的依赖项,但不适用于其他依赖项。我相信如果您将 spring-boot-dependencies 作为显式父级 - 它会起作用。

标签: maven spring-boot jersey dependencies


【解决方案1】:

属性仅从父 POM 继承。这在 maven 文档中有说明(不幸的是,我再也找不到参考资料了)。

【讨论】:

    猜你喜欢
    • 2018-04-09
    • 2019-08-14
    • 2016-08-20
    • 2021-08-28
    • 2019-08-18
    • 2017-11-04
    • 2018-10-09
    • 2021-03-05
    • 2021-12-25
    相关资源
    最近更新 更多