创建Google Java Checkstyle XML文件的自定义版本

问题描述

我目前正在尝试创建一个基于Google样式的Checkstyle样式表,但需要进行一些细微的调整(新的行长和缩进长度。我从Github(https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml)中获取了此文件,但是运行它时出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check (default-cli) on project some-api: Execution default-cli of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:check failed: given name COMPACT_CTOR_DEF -> [Help 1]

Maven插件配置:

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>${checkstyle-maven-plugin.version}</version>
        <configuration>
          <consoleOutput>true</consoleOutput>
          <configLocation>google_checks1.xml</configLocation>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

我需要包括一些依赖项吗?有没有更好的方法可以实现我的目标?任何反馈将不胜感激。

解决方法

上面的评论提供了解决此问题的方法。 需要包括相关性以指定Maven插件的Checkstyle版本。

以下内容对我有用,修复了复制的Google支票中的COMPACT_CTOR_DEF错误

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.1</version>
    <dependencies>
        <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>8.36</version>
        </dependency>
    </dependencies>

    <configuration>
        <configLocation>my_checks.xml</configLocation>
    </configuration>
</plugin>

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...