【发布时间】:2011-12-12 13:11:12
【问题描述】:
我正在将 Maven 项目与现有的自定义 Checkstyle 规则集集成,编译为 jar 并在 Nexus 存储库中可用。该规则集依赖于 Checkstyle 5.0,并且与较新的版本不兼容。
我在配置 Maven 以使用我的规则使用这个较旧的 Checkstyle 版本时遇到问题。
这是我的项目布局:
root/
pom.xml
buildsupport/
pom.xml
src/main/resources/checkstyle
mycompany-coding-rules.xml
src/main/java/com.mycompany.checkstyletest/
CheckstyleViolator.java
[other projects with pom.xml and java source...]
这是我的父母pom.xml:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>buildsupport</artifactId>
<version>X.Y.Z</version>
</dependency>
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>5.0</version>
</dependency>
<dependency>
<groupId>com.mycompany.checkstyle</groupId>
<artifactId>mycompany-checkstyle</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
<configuration>
<configLocation>checkstyle/mycompany-coding-rules.xml</configLocation>
<packageNamesLocation>checkstyle_packages.xml</packageNamesLocation>
</configuration>
</plugin>
</plugins>
</reporting>
...
如果我在 <reporting><plugins><plugin>... 和 <build><pluginManagement><plugins><plugin> 的 maven-checkstyle-plugin 中省略了 <version>2.5</version>,并在根目录中运行 mvn site,则会导致顶级项目失败:
...
[INFO] Generating "Checkstyle" report --- maven-checkstyle-plugin:2.8
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-site) on project mytoplevel-project:
Error during page generation: Error rendering Maven report: Failed during checkstyle configuration:
cannot initialize module TreeWalker - TreeWalker is not allowed as a parent of com.mycompany.checkstyle.checks.coding.ImportOrderCheck -> [Help 1]
在上面的 XML 中添加<version>2.5</version> 可以让顶级项目成功,但在第一个子项目中会看到相同的错误:
...
[INFO] Generating "Checkstyle" report --- maven-checkstyle-plugin:2.5
...
[INFO] mytoplevel-project ................................ SUCCESS [4.528s]
[INFO] buildsupport ...................................... FAILURE [0.489s]
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.0:site (default-site) on project buildsupport:
Error during page generation: Error rendering Maven report: Failed during checkstyle configuration:
cannot initialize module TreeWalker - TreeWalker is not allowed as a parent of com.mycompany.checkstyle.checks.coding.ImportOrderCheck -> [Help 1]
我确定这个错误是由于使用了最新版本的 Checkstyle,而不是 5.0,因为我在使用规则集作为针对 Checkstyle 5.5 的 Eclipse 插件时看到了同样的错误 - 通过回滚 Checkstyle 插件版本来修复它到 5.0。
我不明白的是子项目如何选择错误的 Checkstyle 版本。
【问题讨论】:
标签: maven maven-3 checkstyle