Java google checkstyle Maven
Java google checkstyle Maven
我正在尝试将我的 Maven 项目配置为使用 google java 检查样式,配置如下:
google_checks.xml: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>false</failOnViolation>
<enableFilesSummary>false</enableFilesSummary>
</configuration>
</plugin>
</plugins>
</reporting>
一开始似乎 运行 mvn checkstyle:check
还不错。但是在 运行s 之后,我开始收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project PROJECT: Failed during checkstyle configuration: cannot initialize
module TreeWalker - Token "METHOD_REF" was not found in Acceptable tokens list in check
com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck -> [Help 1]
这是什么意思?为什么它只发生几次,我该如何摆脱它?
Token "METHOD_REF" was not found in Acceptable tokens list in check
com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
您正在尝试对旧版本的 Checkstyle 使用较新的配置。
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml处的配置在master
中,这取决于checkstyle的快照版本。
如果您使用的 google 配置没有任何修改,您需要使用嵌入在 checkstyle 中的配置。参见
否则,您可以集成更新版本的 checkstyle 以与 maven 一起使用。参见
我使用的是 maven-checkstyle-plugin 的 3.0.0 版(目前是最新版本),但仍然出现错误。我通过向插件添加以下依赖项解决了它。
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.11</version>
</dependency>
我正在尝试将我的 Maven 项目配置为使用 google java 检查样式,配置如下:
google_checks.xml: https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<failOnViolation>false</failOnViolation>
<enableFilesSummary>false</enableFilesSummary>
</configuration>
</plugin>
</plugins>
</reporting>
一开始似乎 运行 mvn checkstyle:check
还不错。但是在 运行s 之后,我开始收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project PROJECT: Failed during checkstyle configuration: cannot initialize
module TreeWalker - Token "METHOD_REF" was not found in Acceptable tokens list in check
com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck -> [Help 1]
这是什么意思?为什么它只发生几次,我该如何摆脱它?
Token "METHOD_REF" was not found in Acceptable tokens list in check com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck
您正在尝试对旧版本的 Checkstyle 使用较新的配置。
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml处的配置在master
中,这取决于checkstyle的快照版本。
如果您使用的 google 配置没有任何修改,您需要使用嵌入在 checkstyle 中的配置。参见
否则,您可以集成更新版本的 checkstyle 以与 maven 一起使用。参见
我使用的是 maven-checkstyle-plugin 的 3.0.0 版(目前是最新版本),但仍然出现错误。我通过向插件添加以下依赖项解决了它。
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.11</version>
</dependency>