问题
I am try to use the same Checkstyle configuration file with both Maven and Eclipse. The module SuppressionCommentFilter works as expected in Eclipse, but Maven reports TreeWalker is not allowed as a parent of SuppressionCommentFilter If I move it from TreeWalker to Checker the error goes away, but Checkstyle does not process the ignore comments. I am using Checkstyle 8.12 with Eclipse, but have not found a way to use other than 6.18 with Maven. Since this module had been part of Checkstyle since 3.5 I don't see how that could be the problem. Any suggestions what is wrong?
<module name="Checker">
<property name="severity" value="warning" />
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="SuppressionCommentFilter" />
Mark asked what the looks like, so here is that piece of code.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
The pom and Checkstyle config file are all working correctly other than the
If it is a child of Treewalker I get the error from the Maven plugin, but not from the Eclipse plugin, however I can only get it to work with the Eclipse plugin.
回答1:
I am using Checkstyle 8.12 with Eclipse, but have not found a way to use other than 6.18 with Maven
You must override the dependency in maven to bring in newer versions of Checkstyle. By default, the maven plugin will only use 6.18 but it can be overridden for newer versions.
See https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
回答2:
It appears that you have defined checkstyle as dependency and not as plugin.
Using the guide at Apache Maven Checkstyle I was able to use checkstyle for my personal projects. This is a snippet from the plugins
section of my pom.xml
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<configLocation>yourcheckstylexmlhere.xml</configLocation>
</configuration>
</plugin>
Maskime on GitHub says:
Dear reader if you googled your way here, like I did, the solution is to move the
<module name="SuppressionCommentFilter"/>
under theTreeWalker
module.
I have tried this fix with the version you're using aswell and it does not give the error anymore.
来源:https://stackoverflow.com/questions/52957725/checkstyle-suppressioncommentfilter