Maven Checkstyle:检查不工作

时间:2012-06-19 18:07:36

标签: maven checkstyle

我一直在尝试让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>    

有些不起作用的事情是:

  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插件。
  5. 希望快速回应。

    提前致谢。 瓦玛

3 个答案:

答案 0 :(得分:7)

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

即使您要运行mvn compile,上述配置仍会因为两个配置条目failOnViolationfailOnError而导致构建失败,因为它们都设置为{{1 }}。只要违规次数少于true,删除这些条目并运行mvn compile就应该通过构建。

答案 1 :(得分:0)

  

1.自定义checkstyle的1.configLocation被忽略,并且始终默认为Sun checkstyle。

为此,请使用以下标签:

<properties<checkstyle.config.location>properties/checkstyle.xml</checkstyle.config.location>  </properties>

在项目的POM.xml中,使用checkstyle.this行将位于pom.xml的顶部和底部标记处。

<version>0.0.1-SNAPSHOT</version>

答案 2 :(得分:0)

googe_checks.xml必须位于存在pom.xml的项目中。 mvn checkstyle:检查

<properties>
    <checkstyle.config.location>google_checks.xml</checkstyle.config.location>
    <checkstyle.violationSeverity>warning</checkstyle.violationSeverity>
    <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <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>8.8</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>validate</id>
                        <phase>validate</phase>`
                        <properties>
                            <checkstyle.config.location>google_checks.xml</checkstyle.config.location>
                            <checkstyle.violationSeverity>warning</checkstyle.violationSeverity>
                            <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
                        </properties>

                        <build>
                            <pluginManagement>
                                <plugins>
                                    <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>8.8</version>
                                            </dependency>
                                        </dependencies>
                                        <executions>
                                            <execution>
                                                <id>validate</id>
                                                <phase>validate</phase>
                                                <goals>
                                                    <goal>check</goal>
                                                </goals>
                                            </execution>
                                        </executions>
                                    </plugin>
                                </plugins>
                            </pluginManagement>
                        </build>
                        </project>
                        `
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</project>
相关问题