我有以下 Maven 项目的树结构:
Root/pom.xml
Root/moduleA/pom.xml
Root/moduleA/src/main/java/moduleA/MyClass.java
我想通过 exec-maven 插件在 Root pom.xml 中使用类 moduleA.MyClass 。问题是:如果我将 ModuleA 定义为 pom xml 的模块
Root/pom.xml
<modules>
<module>moduleA</module>
</modules>
我无法将其声明为 Root 的依赖项
Root/pom.xml
<dependencies>
<dependency>
<groupId>Root</groupId>
<artifactId>moduleA</artifactId>
<version>1.0</version>
<scope>install</scope>
</dependency>
</dependencies>
因为它会导致像这样的循环依赖:
[INFO] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='Root:moduleA'}' and 'Vertex{label='Root:moduleA'}' introduces to cycle in the graph Root:moduleA --> Root:moduleA
问题是:如何保持使用 install
目标构建的 moduleA 在 Root pom 上执行 并且能够使用 exec-maven-plugin 执行 moduleA 的类?
最佳答案
我认为你的问题类似于先有鸡还是先有蛋的问题。您的根 POM 是项目的聚合器,它生成您想要使用的 Artifact 。 Artifact 在制造出来之前,是无法使用的。如果您的根 POM(又名聚合器)中需要 moduleA 的类,那么您应该在单独的项目中构建它。 但是您的构建过程可能允许稍后执行 MyClass(不在根 POM 中),您可以将此执行移动到另一个模块并设置对 moduleA 的依赖关系。
关于java - 依赖maven中的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10542374/