最近,我尝试在Jenkins上配置Checkstyle (它使用maven checkstyle结果)。我的问题是eclipse checkstyle显示了不同数量的checkstyle冲突。我对maven和eclipse使用了相同的带有checkstyle规则的xml文件。
Eclipse Checkstyle插件8.12.0 - ~500个违规maven-checkstyle-plugin 3.0.0 -超过5000个违规
对于eclipse错误,我看到的主要是NPath的复杂性和"String在文件中出现X次“的警告。
对于Maven chekstyle 2000,警告是"Line has trailing“(eclipse中没有这样的警告)。还有许多ConstantNameCheck,RegexpSinglelineJavaCheck,VisibilityModifierCheck警告。
我假设这两个插件的工作方式不同,但有没有办法让它显示类似的警告呢?
例如:在简单的项目模块中,我得到了4个违反NPath复杂性的eclipse。对于文件TestHandler.java,它显示"NPath Complexity is 13 allowed is 8“。在maven中,我得到了6个违规,其中大多数都是不同的。唯一类似的说法是,TestHandler.java中的相同短语"NPath Complexity is 13 allowed is 4“。
这是两种检查样式都在使用的xml中检查复合性的方式:
</module>
<module name="CyclomaticComplexity">
<property name="max" value="6" />
</module>
<module name="NPathComplexity">
<property name="max" value="8" />
</module>我在jenkis上运行maven chestyle只是通过使用mvn clean install checkstyle:checkstyle。我使用的是pom中最基本的maven插件。如果需要,可以提供更多信息。
发布于 2018-10-11 19:54:25
我按照你的建议在主pom中做了修改。我还从checkstyle.xml文件中删除了Javadoc违规。目前在eclipse上,我得到了~510,在Intelij ~3100上,在Maven checkstyle上~ 3800。据我所知,这三种情况在违规方面都有所不同。这是我的checkstyle的POM配置的一小段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.18</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>common\code-style\checkstyle2.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin> https://stackoverflow.com/questions/52663865
复制相似问题