问题描述
我目前正在尝试创建一个基于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>