有一个多模块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插件的方式和时间。但是我不需要在中执行checkstyle foo-testkit
,它是从继承的子模块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
在该模块上运行来验证其是否正常运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句