Maven Checkstyle:检查不起作用 [英] Maven Checkstyle:Check not working

查看:244
本文介绍了Maven Checkstyle:检查不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一段时间以来,我一直在尝试让Checkstyle在Eclipse Indigo IDE的Maven中运行.最后,我想我会为此寻求一些专家意见.

I have been working on trying to get Checkstyle working in Maven in the Eclipse Indigo IDE for a while. Finally, I thought I will ask for some expert advise on this.

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

I am using Eclipse Indigo and trying to configure Checkstyle to run in Maven.

下面是我的pom.xml的摘录.只有checkstyle:checkstyle在起作用并正在创建报告.

Below is a snippet of my pom.xml. Only checkstyle:checkstyle is working and creating the reports.

    <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>    

一些不起作用的东西是:

  1. 自定义checkstlye的configLocation被忽略,并且始终默认为Sun checkstlye.
  2. 我无法运行checkstlye:check.我得到以下错误.我应该运行哪个目标,以使checkstyle:check运行. 无法在项目zzz-web上执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.9.1:check(default-cli):您有5950个违反Checkstyle的行为
  3. 如果违反次数超过7000,则配置设置是否适合使构建失败?
  4. Checkstyle报告无法交叉引用该报告中的Java代码.因此,例如,如果我尝试从包中向下钻取到Java类,然后单击违规的行号,则不会将我带到Java文件.也许我没有正确配置jxr插件.
  1. configLocation for a custom checkstlye is being ignored and always default to Sun checkstlye.
  2. I am unable to run checkstlye:check. I get below error. What target should I run so that the checkstyle:check runs. Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.9.1:check (default-cli) on project zzz-web: You have 5950 Checkstyle violations
  3. Is the configuration setting right for failing the build if the number of violations crosses 7000?
  4. The Checkstyle report is unable to cross reference the Java code from the report. So for example, if I try to drill down from the package to the Java classes and then click on line number of the violation, it does not take me to the Java file. Maybe I have not configured the jxr plugin correctly.

希望快速做出反应.

先谢谢了. 瓦玛(Varma)

Thanks in advance. Varma

推荐答案

您已经将maven checkstyle plugincheck目标绑定到了compile阶段.在这种情况下,您需要运行mvn compile才能使用您的配置.运行mvn checkstyle:check将使用默认配置.对于上面的项目1和2,这似乎是最有可能的情况.

You have bound check goal of maven checkstyle plugin to compile phase. That being the case, you would need to run mvn compile for your configurations to be used. Running mvn checkstyle:check will use default configurations. This looks like the most likely case for items 1 and 2 above.

即使您要运行mvn compile,由于两个配置条目failOnViolationfailOnError都被设置为true,因此上述配置仍将因构建失败.只要违反次数小于7000,则删除这些条目并运行mvn compile应该会通过构建.

Even if you were to run mvn compile the above configuration will still fail the build on account of the two configuration entries failOnViolation and failOnError since both of them are set to true. Removing these entries and running mvn compile should pass the build so long as the number of violations are less than 7000.

这篇关于Maven Checkstyle:检查不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆