【问题标题】:maven using parent dependencyManagement with ${project.version} causes dependency in wrong versionmaven 使用带有 ${project.version} 的父dependencyManagement 导致依赖版本错误
【发布时间】:2017-05-13 12:54:04
【问题描述】:

我有以下依赖的结构:child1->child2。

以及两者的父级,使用${project.version}整合依赖管理中的所有版本。

文件夹结构:

+ parent
  + child1
  + child2

请参阅下面的 poms + 完整示例 here

当 child2 的版本设置为 1.0-SNAPSHOT 时,一切正常。

当尝试将 just child2 的版本更改为 2.0-SNAPSHOT 时,我收到以下错误:

Failure to find ...:child1:jar:2.0-SNAPSHOT

为什么 maven 尝试查找版本 child1 2.0 而不是 1.0?

家长:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>info.fastpace.issue.unknowversion</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>child1</module>
        <module>child2</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>info.fastpace.issue.unknowversion</groupId>
                <artifactId>child1</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>info.fastpace.issue.unknowversion</groupId>
                <artifactId>child2</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

孩子1:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <artifactId>child1</artifactId>

    <parent>
        <groupId>info.fastpace.issue.unknowversion</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
</project>

孩子2:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <artifactId>child2</artifactId>
    <version>2.0-SNAPSHOT</version>

    <parent>
        <groupId>info.fastpace.issue.unknowversion</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>info.fastpace.issue.unknowversion</groupId>
            <artifactId>child1</artifactId>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

    标签: maven jar maven-3 pom.xml parent-pom


    【解决方案1】:

    似乎用硬编码的1.0-SNAPSHOT 替换父 pom 中的${project.version} 解决了这个问题。

    不知道为什么更改为硬编码值有效,但至少现在有效。

    【讨论】:

    • 在您的 child2 中,${project.version}2.0-SNAPSHOT,而不是我所期望的 1.0-SNAPSHOT。这意味着对我来说,child2 将在与项目的其余部分(如 parent 和 child1)不同的周期中发布。这意味着 child2 应该是一个单独的项目,因为它有自己的发布周期。
    • 想象一下把它变成1.0.1而不是2.0。现在不一样了吗?
    • 不,没有区别。如果不是所有模块(包括父模块)都具有相同的版本,则多模块构建没有意义......多模块构建旨在让所有模块/子模块具有相同的发布周期和相同的版本......
    猜你喜欢
    • 1970-01-01
    • 2019-07-23
    • 2020-04-17
    • 1970-01-01
    • 2022-06-21
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多