【问题标题】:Maven: Non-resolvable import POM from other moduleMaven:来自其他模块的不可解析的导入 POM
【发布时间】:2017-01-12 20:20:16
【问题描述】:

类似于Maven: Non-resolvable parent POM,但不一样。

我有一个父 pom

<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
</modules>

module1 使用dependencyManagement 定义了一些dependencies

子 pom:module3/pom.xml 正在尝试导入 module1

<parent>
    <artifactId>group</artifactId>
    <groupId>parent</groupId>
    <version>SNAPSHOT</version>
    <relativePath>../</relativePath>
</parent>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>group</groupId>
      <artifactId>module1</artifactId>
      <version>SNAPSHOT</version>
      <scope>import</scope>
      <type>pom</type>
      <!--
      <systemPath>../module1</systemPath>
      -->
    </dependency>
  </dependencies>
</dependencyManagement>

如果我尝试构建父级,就可以了

mvn validate
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:

... ...

[INFO] parent ............................................ SUCCESS [0.128s]
[INFO] module1 ........................................... SUCCESS [0.011s]
[INFO] module2 ........................................... SUCCESS [0.009s]
[INFO] module3 ........................................... SUCCESS [0.009s]
... ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

但如果我在子模块中运行构建,它会失败

mvn validate
[INFO] Scanning for projects...
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project group:module3:SNAPSHOT (/path-tp/project/module3/pom.xml) has 5 errors
[ERROR]     Non-resolvable import POM: Failure to find group:module1:pom:SNAPSHOT in https://repo1.maven.org/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ line 22, column 19 -> [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

我尝试过的

  • 我会尝试使用systemPath,但import 范围不支持它。
  • 我会尝试将 import 范围 dependencies 声明从 module3 移动到父模块,但它未能抱怨循环依赖

如何构建/加载单独的子模块module3,或者有没有其他方法可以将大量的dependencyManagements 拆分为多个子模块?

【问题讨论】:

  • @Tunaki 感谢您提供的信息,它是使用命令行mvn -pl module3 -am 工作的,但实际上我想从其他一些实用程序加载子模块 pom,例如“从 jetbrains IDEA 运行生命周期”/“使用 ant 集成 (maven-ant) 加载依赖项”,对于这些情况没有更好的支持。也许我不得不将所有 dependencyManagements 移动到父 pom

标签: maven dependency-management circular-dependency multi-module


【解决方案1】:

在父级工作时,Maven 能够解决模块之间的依赖关系。

但如果你在模块 3 中工作,它不知道模块 1 是项目的同级模块。

如果你想直接在模块 3 中工作,你需要先安装模块 1。

【讨论】:

  • 这就是为什么我尝试使用systemPath但发现maven不支持这种类型的导入
  • @WilliamLeung 转到项目的根级别,创建一个mvn install。之后使用mvn -pl ... 永远不要更改到文件夹中......并且 systemPath 将永远无法工作......
猜你喜欢
  • 2016-10-25
  • 2011-11-28
  • 2020-03-20
  • 2021-11-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2019-08-14
  • 2021-11-12
相关资源
最近更新 更多