Maven Checkstyle:检查不工作

AVa*_*rma 5 checkstyle maven

我一直在尝试让Checkstyle在Eclipse Indigo IDE中使用Maven工作一段时间.最后,我想我会就此问一些专家建议.

我正在使用Eclipse Indigo并尝试将Checkstyle配置为在Maven中运行.

下面是我的pom.xml的片段.只有checkstyle:checkstyle工作和创建报告.

    <profile>
        <id>checkstyle-profile</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>2.9.1</version>
                    <configuration>
                        <includeTestSourceDirectory>true</includeTestSourceDirectory>
                        <configLocation>${basedir}/src/main/resources/maven_checks.xml</configLocation>
                    </configuration>
                    <executions>
                        <execution>
                            <id>checkstyle-check</id>
                            <goals>
                                <goal>check</goal>
                            </goals>
                            <phase>compile</phase>  <!--  Default is "verify" -->
                            <configuration>
                                <violationSeverity>error</violationSeverity>
                                <maxAllowedViolations>7000</maxAllowedViolations>
                                <failOnViolation>true</failOnViolation>
                                <failsOnError>true</failsOnError>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>   
            </plugins>
        </build>
    </profile>

</profiles>

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <configLocation>${basedir}/src/main/resources/maven_checks.xml</configLocation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jxr-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
</reporting>    
Run Code Online (Sandbox Code Playgroud)

一些不起作用的事情是:

  1. 正在忽略自定义checkstlye的configLocation,并且始终默认为Sun checkstlye.
  2. 我无法跑checkstlye:check.我得到以下错误.我应该运行什么目标才能checkstyle:check运行.无法org.apache.maven.plugins:maven-checkstyle-plugin:2.9.1:check在项目zzz-web上执行目标(default-cli):您有5950个Checkstyle违规
  3. 如果违规次数超过7000,配置设置是否正确?
  4. Checkstyle报告无法交叉引用报告中的Java代码.因此,例如,如果我尝试从包向下钻取到Java类,然后单击违规的行号,则不会将我带到Java文件.也许我还没有正确配置jxr插件.

希望快速回应.

提前致谢.瓦尔马

Rag*_*ram 7

您已绑定check的目标maven checkstyle plugin,以compile期.在这种情况下,您需要运行mvn compile您的配置才能使用.运行mvn checkstyle:check将使用默认配置.这看起来像上面第1项和第2项最可能的情况.

即使您要运行mvn compile上述配置,仍然会因为两个配置条目failOnViolation而无法构建,failOnError因为它们都设置为true.mvn compile只要违规次数小于,删除这些条目并运行就应该通过构建7000.

  • @AVarma.当然,您可能需要upvote和/或[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),以便将来帮助其他人. (2认同)