6

当我运行检查目标时,我似乎无法弄清楚如何让 maven-checkstyle-plugin 向控制台打印警告。

如果我配置为:

<module name="Checker">
    <module name="TreeWalker">
        <module name="NPathComplexity">
            <property name="max" value="5" />
            <property name="severity" value="warning" />
        </module>
    </module>
</module>

...我在控制台中什么也看不到,并且检查没有失败。如果我将严重性更改为错误,则检查失败。

有任何想法吗?我错过了什么吗?

插件配置如下

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    <logViolationsToConsole>true</logViolationsToConsole>
                    <configLocation>
                        rules.xml</configLocation>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
4

3 回答 3

6

我有一个类似的问题。这个配置对我有用。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.9.1</version>
    <configuration>
        <consoleOutput>true</consoleOutput>
    </configuration>
    <executions>
        <execution>
           <id>checkstyle</id>
           <goals>
               <goal>checkstyle</goal>
           </goals>
           <phase>prepare-package</phase>
        </execution>
    </executions>
</plugin>
于 2012-08-12T02:53:42.067 回答
1

添加<violationSeverity>warning</violationSeverity><configuration>pom.xml 中对我有用:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <logViolationsToConsole>true</logViolationsToConsole>
                <configLocation>checkstyle.xml</configLocation>
                <violationSeverity>warning</violationSeverity>
            </configuration>
            <executions>
            ...
            </executions>
            ...
        </plugin>

另外,我的 checkstyle.xml 中有这个:

       <module name="Checker">

          <module name="SeverityMatchFilter">
              <!-- report all violations except ignore -->
              <property name="severity" value="ignore"/>
              <property name="acceptOnMatch" value="false"/>
          </module>

          ...

      </module>
于 2016-10-05T17:37:39.383 回答
0

我假设您必须明确添加检查目标以将信息打印到控制台,如文档中所述

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.9.1</version>
    <executions>
      <execute>
        <id>check</id>
        <goals><goal>check</goal></goals>
        <phase>prepare-package</phase>
      <execute>
    </executions>
  </plugin>

根据您调用 mvn 的方式,您需要更改完成检查的阶段。maven-checkstyle-plugin 的默认绑定是验证阶段。要么在执行块中给出明确的阶段,要么只执行 mvn clean verify 并且可以省略阶段条目。

于 2012-05-07T19:55:51.917 回答