【问题标题】:Maven Checkstyle:Check not workingMaven Checkstyle:检查不起作用
【发布时间】:2012-06-21 20:02:00
【问题描述】:

一段时间以来,我一直在努力让 Checkstyle 在 Eclipse Indigo IDE 中的 Maven 中工作。最后,我想我会在这方面寻求一些专家的建议。

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

下面是我的 pom.xml 的 sn-p。只有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 插件。

希望尽快回复。

提前致谢。 瓦玛

【问题讨论】:

    标签: maven checkstyle


    【解决方案1】:

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

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

    【讨论】:

    【解决方案2】:

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

    为此,请使用以下标签:

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

    在您使用 checkstyle 的项目的 POM.xml 中。此行将位于 pom.xml 的顶部和下方标记。

    <version>0.0.1-SNAPSHOT</version>
    

    【讨论】:

      【解决方案3】:

      googe_checks.xml 必须位于 pom.xml 所在的项目中。 mvn checkstyle:check

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-22
        • 2012-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-07
        • 2012-09-29
        • 1970-01-01
        相关资源
        最近更新 更多