【问题标题】:Maven checkstyle not running as part of buildMaven checkstyle 未作为构建的一部分运行
【发布时间】:2014-11-05 20:02:06
【问题描述】:

我完全不知道为什么不。结构是这样的:

使用 mvn checkstyle:check 创建报告(我在报告部分有相同的设置),但 build 将插件视为不存在。如果我更改 checkstyle 版本,它不会下载它,等等。本质上它会将此配置视为不可见。

<build>
   <pluginManagement>
         <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-checkstyle-plugin</artifactId>
              <version>2.13</version>

              <configuration>
                <configLocation>checkstyle.xml</configLocation>
                <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                <maxAllowedViolations>2500</maxAllowedViolations>
                <consoleOutput>true</consoleOutput>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
              </configuration>

              <executions>
                <execution>
                  <id>checkstyle</id>
                  <goals>
                    <goal>check</goal>
                  </goals>
                  <configuration>

                    <encoding>UTF-8</encoding>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <failOnViolation>true</failOnViolation>
                  </configuration>
                </execution>
              </executions>
            </plugin>
.....
</plugins>
</pluginManagement>
</build>

【问题讨论】:

  • 直到你把它放在构建/插件中,它只是潜在的,而不是实际的。它没有默认绑定。
  • 好的,我明白了。
  • @bmargulies 你的意思是添加相位元素,例如。验证?

标签: maven checkstyle


【解决方案1】:

您可以按如下方式将插件添加到 pom 中,它将作为您构建的一部分执行(mvn clean install):

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <configLocation>checkstyle.xml</configLocation>
    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
    <consoleOutput>true</consoleOutput>
    <maxAllowedViolations>2500</maxAllowedViolations>
    <failsOnError>true</failsOnError>
    <failOnViolation>true</failOnViolation>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>

另请参阅:Checkstyle not working

实际上,对于大多数配置参数(除了 failsOnError 之外的所有配置参数,它没有“用户属性”),您也可以将它们作为属性放在 pom.xml 中:

  <properties>
    ...
    <checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
    <checkstyle.suppressions.location>checkstyle-suppressions.xml</checkstyle.suppressions.location>
    <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
    <checkstyle.maxAllowedViolations>2500</checkstyle.maxAllowedViolations>
    <checkstyle.failOnViolation>true</checkstyle.failOnViolation>
  </properties>

为了方便起见,您可以将它们从插件配置部分中删除,尽管这两种方法都有效。有关“用户属性”值等,请参阅 https://maven.apache.org/plugins/maven-checkstyle-plugin/check-mojo.html

【讨论】:

    猜你喜欢
    • 2013-11-09
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2017-12-30
    • 1970-01-01
    • 2012-06-21
    • 2018-02-26
    • 1970-01-01
    相关资源
    最近更新 更多