标签: maven-checkstyle-plugin

maven-checkstyle-plugin 不适用于 macOS 上的 google_checks.xml

我有一个 Java / Maven 项目,我在家里用 Windows 构建并正确执行了 checkstyle。它使用内置规则集,但我也尝试了外部文件。

查看相同的代码 / pom.xml 它似乎不适用于 macOS。奇怪的是,如果我使用sun_checks.xml它工作正常。使用 8.8 没有什么区别。

<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.7</version>
    </dependency>
  </dependencies>
  <configuration>
    <encoding>UTF-8</encoding>
    <configLocation>google_checks.xml</configLocation>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果我这样运行它,它会在不做任何检查的情况下完成:

mvn checkstyle:check -X
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T18:58:13+11:00)
Maven home: /gdev/apache-maven
Java version: 1.8.0_161, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.3", arch: "x86_64", family: "mac"
[..]
[DEBUG] The resource 'google_checks.xml' was found as jar:file:/Users/udoheld/.m2/repository/com/puppycrawl/tools/checkstyle/8.7/checkstyle-8.7.jar!/google_checks.xml. …
Run Code Online (Sandbox Code Playgroud)

java macos checkstyle maven maven-checkstyle-plugin

5
推荐指数
1
解决办法
2877
查看次数

SuppressionCommentFilter 不允许作为 Checker 中的子项”

错误:无法解析 Checkstyle 规则文件。SuppressionCommentFilter 不允许作为 Checker 中的子文件 60 年代的文件已被列入黑名单。

注意:我使用的 Checkstyle 版本是 7.1.2。

这是一个看起来完全有效的配置,

<module name="Checker">
  <property name="severity" value="warning" />
  <module name="TreeWalker">
    ...
  </module>
  ...
  <module name="SuppressWarningsFilter" />
  <module name="SuppressionFilter">
    <property name="file" value="${config_loc}/suppressions.xml"/>
  </module>
  <module name="SuppressionCommentFilter">
    <property name="checkC" value="false" />
  </module>
  ...
</module>
Run Code Online (Sandbox Code Playgroud)

suppress-warnings intellij-plugin intellij-14 maven-checkstyle-plugin

5
推荐指数
1
解决办法
3497
查看次数

checkstyle 未选取 src/test 文件夹

我在 maven build 中添加了 checkstyle 但由于某种原因它只检查 src/main 文件夹并忽略 src/test 文件夹,这是我的项目结构:

Proj
 - Module A
   - src
     - main
       - java
       - resources
     - test
       - java
       - resources
 - Module B
   - src
     - main
       - java
       - resources
     - test
       - java
       - resources
 pom.xml
 checkstyle.xml
Run Code Online (Sandbox Code Playgroud)

和我的 pom.xml

     <properties>
        <checkstyle.version>3.0.0</checkstyle.version>
        <checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
        <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
        <checkstyle.failOnViolation>true</checkstyle.failOnViolation>
        <encoding>UTF-8</encoding>
    </properties>

   <build>
        <pluginManagement>
            <plugins>
                ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>${checkstyle.version}</version>
                    <dependencies>
                        <dependency>
                            <groupId>com.puppycrawl.tools</groupId>
                            <artifactId>checkstyle</artifactId>
                            <version>8.18</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>validate</id>
                            <phase>validate</phase>
                            <configuration>
                                <testSourceDirectories>src/test/java</testSourceDirectories>

         <includeTestSourceDirectory>true</includeTestSourceDirectory>
                            </configuration>
                            <goals> …
Run Code Online (Sandbox Code Playgroud)

maven-checkstyle-plugin

4
推荐指数
1
解决办法
3510
查看次数

Checkstyle LineLength 配置不起作用

在尝试添加maven-checkstyle-plugin到我的 Java 项目时,我遇到了一些奇怪的问题。checkstyle 版本是 3.1.0,它使用 checkstyle 版本 8.19。下面是checkstyle.xml项目正在使用的:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="TreeWalker">
    <module name="LineLength">
        <property name="max" value="120"/>
    </module>
</module>
Run Code Online (Sandbox Code Playgroud)

和我在 pom.xml 上的配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <configLocation>checkstyle.xml</configLocation>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

现在,当我运行时mvn checkstyle:check会显示以下消息:

[错误] 无法在项目 myproject 上执行目标 org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default-cli):在 checkstyle 配置期间失败:在 Checker 中不允许 LineLength 作为孩子 - > [帮助1]

如果我更新 checkstyle 使其看起来像这样

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="LineLength">
        <property name="max" value="120"/>
</module> …
Run Code Online (Sandbox Code Playgroud)

java checkstyle maven maven-checkstyle-plugin

4
推荐指数
2
解决办法
4678
查看次数

Checkstyle升级后如何验证自定义配置xml

我已将 maven-checkstyle-plugin 从 2.17 升级到 3.1.1,在运行 mvn checkstyle:checkstyle 时,我遇到了许多运行时错误,例如(最困难的部分是错误一次显示 1 - 这意味着您修复了第一个错误,然后第二个错误显示...):

 1. Failed during checkstyle configuration: cannot initialize module TreeWalker - Unable to instantiate 'FileContentsHolder' class,
 2. cannot initialize module TreeWalker - TreeWalker is not allowed as a parent of LineLength Please review 'Parent Module' section for this Check in web documentation if Check is standard.
 3. SuppressionCommentFilter is not allowed as a child in Checker
Run Code Online (Sandbox Code Playgroud)

这是因为升级到最新插件版本后,版本从 6.* 升级到了 8.*。

我试图找到一些验证器来告诉我 XML 不再有效,但我找不到任何验证器,有这样的工具吗?

java checkstyle maven maven-checkstyle-plugin

4
推荐指数
1
解决办法
1596
查看次数

禁用 checkstyle maven 插件生成的源目录

在一个多模块项目中,有一个在目录中生成一些源代码target/generated-sources/xjc3/com/...,我试图使 Maven checkstyle 插件跳过这个生成的源目录。尽管尝试了许多标记语法<excludes>,但它仍然扫描此源目录。有谁知道如何从审核中删除这个生成的源目录?

Maven 插件配置

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-checkstyle-plugin</artifactId>
      <version>3.0.0</version>
      <dependencies>
        <dependency>
          <groupId>org.apache.cloudstack</groupId>
          <artifactId>checkstyle</artifactId>
          <version>${project.version}</version>
        </dependency>
        <dependency>
          <groupId>com.puppycrawl.tools</groupId>
          <artifactId>checkstyle</artifactId>
          <version>8.7</version>
        </dependency>
      </dependencies>
      <executions>
        <execution>
          <id>cloudstack-checkstyle</id>
          <phase>validate</phase>
          <goals>
            <goal>check</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <failsOnError>true</failsOnError>
        <configLocation>cloud-style.xml</configLocation>
        <consoleOutput>true</consoleOutput>
        <includeTestSourceDirectory>true</includeTestSourceDirectory>
        <includes>**\/*.java</includes>
        <excludes>**\/deps\/,**\/test\/,**\/target\/,**\/bin\/,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat,**\/apidoc\/,**\/generated-sources\/,**\/generated-sources\/*,**\/generated-sources\/**,**\/generated-sources\/**\/*.*,**/generated-sources/**/*.*,**/generated-sources/**/*,**/generated-sources/**,**/generated-sources/*,**/generated-sources/*.*</excludes>
      </configuration>
    </plugin>
Run Code Online (Sandbox Code Playgroud)

Maven 运行调试输出

这是插件调试输出,它显示它不断包含生成的源目录:

[INFO] --- maven-checkstyle-plugin:3.0.0:check (cloudstack-checkstyle) @ cloud-plugin-network-vcs ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0, parent: sun.misc.Launcher$AppClassLoader@74a14482]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check' with basic configurator -->
[DEBUG]   (f) cacheFile = /home/marco/code/cloudstack-public/plugins/network-elements/brocade-vcs/target/checkstyle-cachefile
[DEBUG]   (f) …
Run Code Online (Sandbox Code Playgroud)

checkstyle maven maven-checkstyle-plugin

3
推荐指数
1
解决办法
7501
查看次数

使用 google_checks 时,Checkstyle Maven 插件执行不会因错误而失败

我在版本 3.0.0 和 Checkstyle 6.18 中使用Maven Checkstyle 插件

这是我的初始配置:

<properties>
    <maven.checkstyle.plugin.version>3.0.0</maven.checkstyle.plugin.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${maven.checkstyle.plugin.version}</version>
            <configuration>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

运行mvn checkstyle:checkstyle将导致构建失败,因为存在 checkstyle 错误。这是预期的。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (default-cli) on project demo: Failed during checkstyle execution: There are 311 errors reported by Checkstyle 6.18 with sun_checks.xml ruleset. -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

但是,当我使用google_checks.xml 与 Maven 插件捆绑在一起的 which时,构建成功而没有任何错误(target/checkstyle-report.xml尽管仍然显示问题)。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>${maven.checkstyle.plugin.version}</version>
    <configuration>
        <configLocation>google_checks.xml</configLocation>
        <failsOnError>true</failsOnError>
        <failOnViolation>true</failOnViolation>
    </configuration>
</plugin> …
Run Code Online (Sandbox Code Playgroud)

java checkstyle maven maven-checkstyle-plugin

3
推荐指数
1
解决办法
2408
查看次数

从 maven-checkstyle-plugin 扫描中排除 *target* 目录

我在 pom.xml 中使用 Apache Maven Checkstyle 插件。我试图从检查式扫描中排除目标目录,但到目前为止还没有运气。这是我正在尝试的 pom 代码。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <executions>
                <execution>
                    <id>checkstyle-check</id>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configLocation>checkstyles.xml</configLocation>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
                <consoleOutput>true</consoleOutput>
                <includes>**\/*.java,**\/*.groovy</includes>
                <excludes>**WHAT GOES HERE TO EXCLUDE THE TARGET DIRECTORY**</excludes>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

java pom.xml maven maven-checkstyle-plugin

2
推荐指数
1
解决办法
6045
查看次数

maven-checkstyle-plugin 不会在自定义规则上执行

我正在尝试maven-checkstyle-plugin按照官方文档添加以下内容作为构建检查的一部分。但是我尝试过,我无法使用自定义规则运行它。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
                <encoding>UTF-8</encoding>
                <consoleOutput>true</consoleOutput>
                <failsOnError>true</failsOnError>
                <linkXRef>false</linkXRef>
            </configuration>
            <executions>
                <execution>
                    <id>validate</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

checkstyle.xml只包含的具体内容在此发现google_checks.xml

执行后mvn checkstyle:check,我总是被击中


[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (default-cli) on project XXXXXXX: Failed during checkstyle configuration: cannot initialize module LineLength - Property 'fileExtensions' does not exist, please check the documentation
Run Code Online (Sandbox Code Playgroud)

maven-checkstyle-plugin

2
推荐指数
1
解决办法
2764
查看次数