【问题标题】:Can't provide version ranges in the maven dependency management import scope无法在 Maven 依赖管理导入范围内提供版本范围
【发布时间】:2019-05-20 13:38:43
【问题描述】:

我有一个使用 maven 管理的大型 java 项目。 我们使用 Maven 3 进行管理(特别是 3.6.0)。

在项目中,有一个带有runtime-v5.pom.xml 的子=项目。 在说pom,有一个版本属性

<properties>
    <platform-v5.version>73.2.05</platform-v5.version>
</properties>

文件后面会用到

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.company.thing.platform</groupId>
            <artifactId>platform-parent</artifactId>
            <version>${platform-v5.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.company.release</groupId>
            <artifactId>platform-v5</artifactId>
            <version>${platform-v5.version}</version>
            <type>resolved-pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

我的目标是让 maven 引入最新版本的平台,我不想每次都更新这个文件中的版本。我认为将特定版本更改为范围将使项目始终根据给定范围拉入最新版本。

platform-v5.version 设置为特定的现有版本时,它构建得很好,但是当将版本设置为[73.2.05,) 之类的范围时,我收到诸如

之类的错误
[INFO] Scanning for projects...
[INFO] Downloading from all_global_universal: https://nexus.company/platform-parent/%5B73.2.05,).pom
[ERROR] Some problems were encountered while processing the POMs:
[ERROR] Non-resolvable import POM: Could not find artifact com.company.thing.platform:platform-parent:pom:[73.2.05,) in all_global_universal (https://nexus.company/content/groups/all_global_universal) @ com.company:runtime-v5:[unknown-version], path/to/runtime-v5.pom.xml, line XX, column YY
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.company:runtime-v5:1.0.2 (path/to/runtime-v5.pom.xml) has 1 error
[ERROR]     Non-resolvable import POM: Could not find artifact com.company.thing.platform:platform-parent:pom:[73.2.05,) in all_global_universal (https://nexus.company/content/groups/all_global_universal) @ com.company:runtime-v5:[unknown-version], path/to/runtime-v5.pom.xml, line XX, column YY -> [Help 2]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

本质上,我想知道:为什么不能在maven依赖管理导入范围内提供版本范围?

【问题讨论】:

    标签: java maven dependencies versioning


    【解决方案1】:

    虽然版本范围并未完全弃用,但它们不再被视为最佳实践。现代方法是在构建之前运行适当的更新目标,以便 pom 中的版本号是可用的最新版本号。

    【讨论】:

    • 当尝试运行mvn versions:resolve-ranges --file runtime-v5.pom.xml mvn 时似乎仍然无法解析版本范围;它会引发与上面列出的相同的错误。我已经在同一个项目中使用其他pom 文件运行此命令,并且该命令工作正常。您对为什么会这样有什么建议吗?
    • 不知道目标能否正确解析属性。
    【解决方案2】:

    这是Using maven dependency management import scope with version ranges的副本

    这个 Maven 问题已经解决,将在 Maven 4.0.0 中发布:https://issues.apache.org/jira/browse/MNG-4463

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-12
      • 2018-05-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-17
      • 2016-05-28
      • 1970-01-01
      • 2013-02-19
      相关资源
      最近更新 更多