英文:
Creating a customized version of the Google Java Checkstyle XML file
问题
我目前正在尝试创建一个基于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>
是否需要包含一些依赖项?有更好的实现方法吗?非常感谢您的任何反馈。
英文:
I am currently trying to create a checkstyle stylesheet that is based off of the Google one, but with some minor tweaks (new line length and indentation lengths. I grabbed this file off of Github (https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml), but I am getting the following error when I run it:
[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 configuration:
<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>
Are there some dependencies that I need to include? Is there a better way of achieving my goal? Any feedback would be appreciated.
答案1
得分: 3
以下是翻译好的内容:
上面的评论提供了解决此问题的方法。
需要包含依赖项以指定用于 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>
英文:
The comment above gives the way to fix this issue.
Need to include the dependency to specify the checkstyle version for the maven plugin.
The following worked for me, fixing the COMPACT_CTOR_DEF error from the copied google checks
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论