【问题标题】:Error using checkstyle/google_checks.xml with maven-checkstyle-plugin使用带有 maven-checkstyle-plugin 的 checkstyle/google_checks.xml 时出错
【发布时间】:2015-02-05 08:32:17
【问题描述】:

我正在尝试将checkstyles google_checks.xmlmaven-checkstyle-plugin 一起使用。如果我将 google_checks.xml 与最新的 checkstyle intelliJ 插件一起使用,一切都是正确的,但是当我尝试通过 maven-checkstyle 插件对其进行配置时,我会收到此错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check (default-cli) on project XX_XX_XX: Failed during checkstyle configuration: cannot initialize module TreeWalker - Unable to instantiate AvoidEscapedUnicodeCharacters:
Unable to instantiate AvoidEscapedUnicodeCharactersCheck 

我的 pom.xml 看起来像这样:

   <project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
    [...]
    <checkstyle.file.path>develop/checkstyle/google_checks.xml</checkstyle.file.path>
</properties>
[...]
<build>
    <plugins>
        [...]
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.13</version>
            <configuration>
                <configLocation>${checkstyle.file.path}</configLocation>
                <failOnViolation>false</failOnViolation>
            </configuration>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <configLocation>${checkstyle.file.path}</configLocation>
                <failOnViolation>false</failOnViolation>
            </configuration>
        </plugin>
    </plugins>
</reporting>

你们对可能出现的问题有什么建议吗?

【问题讨论】:

    标签: java maven intellij-idea checkstyle


    【解决方案1】:

    Maven checkstyle plugin 使用 checkstyle 5.7(插件描述的第一行)。

    Checkstyle 5.7 没有此检查(请参阅 grepcode 上的 checks package)。

    您需要禁用此检查或等待MCHECKSTYLE-261 的官方修复。

    【讨论】:

      【解决方案2】:

      通过将 checkstyle-dependency 手动更新为 latest stable version 来解决此问题:

              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-checkstyle-plugin</artifactId>
                  <version>2.13</version>
                  <dependencies>
                      <dependency>
                          <groupId>com.puppycrawl.tools</groupId>
                          <artifactId>checkstyle</artifactId>
                          <version>${checkstyle.latest.version}</version>
                      </dependency>
                  </dependencies>
                  <configuration>
                      <configLocation>${checkstyle.file.path}</configLocation>
                      <failOnViolation>false</failOnViolation>
                  </configuration>
              </plugin>
      

      【讨论】:

        【解决方案3】:

        我在

        做一个演示

        https://github.com/favoorr/Maven-Checkstyle-Multimodule-Use

        多模块并使用 Google Chechstyle

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-08-17
          • 2019-12-02
          • 1970-01-01
          • 2013-11-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-08-31
          相关资源
          最近更新 更多