有一个多模块 Maven-3 项目,其中一个子模块用作 <dependency>
在所有其他模块中。同时,所有的子模块都继承自父模块。这样的结构导致循环依赖。我该如何解决?
项目结构比较典型:
/foo
/foo-testkit
/foo-core
这是父级 foo/pom.xml
:
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>checkstyle/checks.xml</configLocation>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>foo-testkit</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
父foo/pom.xml
我指定如何以及何时必须在每个子模块中执行 checkstyle 插件。但我不需要在 foo-testkit
中执行 checkstyle| , 这是一个继承自 foo
的子模块, 但同时又是一个依赖..
最佳答案
一种方法是通过将以下内容添加到 foo-testkit 的 pom.xml 文件来禁用模块 foo-testkit 的 checkstyle 插件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
如果您不喜欢,另一种方法是将 checkstyle 插件配置从 build/plugins 移动到父 pom.xml 文件中的 build/pluginManagment/plugins。然后在每个要执行 checkstyle 的模块中,将其添加到每个模块的 pom.xml 文件的 build/plugins 部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
这将调用该模块的插件,并且将应用在 pluginManagement 部分下的父 pom.xml 中指定的配置。您可以通过在该模块上运行 mvn help:effective-pom
来验证它是否正常工作。
关于java - 如何解决补充 Maven 子模块中的循环依赖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4503601/