我有一个包含多个模块的Maven项目,包括org.eclipse.cdt.core
。出于某种原因,客户也希望构建org.eclipse.cdt.core
。
我想生成一个聚合的Checkstyle报告,从中排除一些文件,包括所有org.eclipse.cdt.core.*
(包括子包)类。
为此,我将excludes
标记指定为
<excludes>**/org/eclipse/cdt/core/**/*,org.eclipse.cdt.core/src/**/*,../org.eclipse.cdt.core/src/**/*,org.eclipse.cdt.core/**/*</excludes>
然后我运行mvn clean checkstyle-aggregate site
,打开文件target/checkstyle-result.xml
并在其中找到以下行:
<file name="C:\dev\ide\org.eclipse.cdt.core\src\org\eclipse\cdt\core\AbstractExecutableExtensionBase.java">
<error line="0" severity="error" message="File does not end with a newline." source="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
<error line="10" severity="error" message="Line is longer than 80 characters (found 81)." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
<error line="15" severity="error" message="Line is longer than 80 characters (found 83)." source="com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck"/>
这意味着我的<excludes>
代码无效。
然后,我把行
<properties>
<checkstyle.skip>true</checkstyle.skip>
</properties>
到要从Checkstyle中排除的所有模块的pom.xml
个文件中,但它没有帮助。
如何生成CheckStyle报告(XML或HTML),但没有某些模块的结果(除了取180 MB大target/checkstyle-result.xml
并从那里删除所有“错误”文件之外)?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mycompany-parentproject</groupId>
<artifactId>com.mycompany.parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho-version>0.21.0</tycho-version>
<tycho-extras-version>0.21.0</tycho-extras-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antrun-version>1.7</antrun-version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>Codehaus repository</id>
<url>http://repository.codehaus.org/</url>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<site>
<id>${project.artifactId}-site</id>
<url>${project.baseUri}</url>
</site>
</distributionManagement>
<build>
<plugins>
<plugin>
<!-- enable tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
</environments>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-versions-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<format>'mycompany_'yyyyMMddHHmm</format>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../com.mycompany.module1</module>
<module>../com.mycompany.module2</module>
<module>../com.mycompany.module3</module>
<module>../org.eclipse.cdt.core</module>
</modules>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<configuration>
<configLocation>sun-coding-standard.checkstyle.xml</configLocation>
<excludes>**/org/eclipse/cdt/core/**/*,org.eclipse.cdt.core/src/**/*,../org.eclipse.cdt.core/src/**/*,org.eclipse.cdt.core/**/*</excludes>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<reportSets>
<reportSet>
<id>aggregate</id>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<xmlOutput>true</xmlOutput>
</configuration>
<reportSets>
<reportSet>
<id>aggregate</id>
<reports>
<report>aggregate</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</reportPlugins>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
更新1(25.09.2014 13:03 MSK):试图通过添加
来使用抑制过滤器<configuration>
<configLocation>sun-coding-standard.checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
checkstyle-suppressions.xml 等于
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files="[\\/]org.eclipse.cdt.core[\\/]" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]org[\\/]eclipse[\\/]cdt[\\/]core[\\/]" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]org.eclipse.cdt.core[\\/]" checks="."/>
<suppress files="[\\/]org[\\/]eclipse[\\/]cdt[\\/]core[\\/]" checks="."/>
</suppressions>
没有用。
将<suppressionsFileExpression>checkstyle.suppressions.files</suppressionsFileExpression>
添加到上述<configuration>
部分也没有任何帮助。
答案 0 :(得分:0)
这可能是一个愚蠢的问题,但你的checkstyle定义中还有更多的代码吗?
通常我们会这样:
<fileset dir="src">
<include name="**/*.java"/>
<exclude name="com/myproject/util/*.java"/>
</fileset>
您需要说明从何处开始扫描(源文件夹),要包含的文件类型(通常为* .java)以及要排除的内容。 在我看来,你试图验证太多,而不是必要的东西。 Checkstyle用于验证开发人员代码,而不是IDE配置文件。