将module-info.java
文件添加到我的项目后,我的checkstyle插件开始失败:
[错误]无法执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.17:检查(default-cli)项目电子邮件:在checkstyle配置期间失败:在分析文件/ home/xxx /期间发生NoViableAltException IdeaProjects/blynk服务器/服务器/通知/电子邮件/ src目录/主/ JAVA/module-info.java.意外令牌:模块 - > [帮助1]
我试过了
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
Run Code Online (Sandbox Code Playgroud)
然而,它失败了:
[错误]无法执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check(default-cli)on project blynk:checkstyle配置失败:无法初始化模块BeforeExecutionExclusionFileFilter - 无法实例化'BeforeExecutionExclusionFileFilter'类,也无法将其实例化为com.puppycrawl.tools.checkstyle.checks.annotation.BeforeExecutionExclusionFileFilter
module-info.java
在checkstyle期间为maven-checkstyle-plugin 跳过文件的正确方法是什么?
我的项目强制执行严格的样式,因此我将maven-checkstyle-plugin
运行作为构建的一部分。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle.version}</version> // 3.0.0
<executions>
<execution>
<id>checkstyle</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<configLocation>google_checks.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
当我运行构建时,我看到插件正在运行并检查样式,但是当存在检查样式问题时它应该会失败,因为我true
设置了标志。
它继续运行并且构建成功的任何原因?
[INFO] --- maven-checkstyle-plugin:3.0.0:check (checkstyle) @ demo-api ---
[INFO] Starting audit...
...
...
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:9:57: Parameter name 'BASE_PATH' must match pattern '^[a-z][a-z0-9][a-zA-Z0-9]*$'. [ParameterName]
[WARN] /Users/jeeves/git/jeeves/demo/src/main/java/com/demo/api/routes/UserRoutes.java:13: Line is longer than 100 characters (found 102). [LineLength]
Audit done.
...
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.153 s
[INFO] Finished …
Run Code Online (Sandbox Code Playgroud) 我有一个 checkstyle.xml 文件来检查格式违规。有没有办法提供 checkstyle.xml 作为 diffplug/spotless formatter 的输入。正在使用 Java8,完美的版本是 2.11.0 。如果使用spotless::apply 可以做到这一点,我们就可以删除所有样式违规。Maven 版本是 3.6.3 。目前正在使用 google-java-format 。
code-formatting checkstyle maven-checkstyle-plugin google-java-format spotless
关于 SonarQube + Checkstyle 警告的小问题。
目前,在我的应用程序中,在我的 pom 中,我使用以下 Checkstyle 插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<outputFile>.out/reports/checkstyle/checkstyle-result.xml</outputFile>
<outputDirectory>target/reports/checkstyle</outputDirectory>
<outputFileFormat>xml</outputFileFormat>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这个插件正在完成它的工作,不用担心。
当我运行 SonarQube 时,我收到此警告
Old version of checkstyle detected. Consider updating to >= v8.30
For more information see: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
Run Code Online (Sandbox Code Playgroud)
我显然去阅读了该网站,但我仍然很难理解。
我拥有的 Checkstyle 插件是最新的已知版本,版本 3.1.2,在 Maven 中心等上进行了检查。
在 SonarQube 中,我运行的是最新版本 8.9 LTS,以及最新版本的 Checkstyle 插件。
请问我缺少什么?我是否使用了某种错误的插件?
我正在尝试在我们的项目中设置 checkstyle - 但似乎Maven
(v3.8.3) 或maven-checkstyle-plugin
(v3.1.1) 本身不知道 Java 14 record
(我们使用 Java 17)。
Caused by: java.lang.IllegalStateException: /Users/dmitry.adonin/IdeaProjects/raap/src/main/java/com/xxx/web/dto/Request.java:3:8: unexpected token: record
at com.puppycrawl.tools.checkstyle.JavaParser$1.reportError (JavaParser.java:93)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.typeDefinition (GeneratedJavaRecognizer.java:411)
at com.puppycrawl.tools.checkstyle.grammar.GeneratedJavaRecognizer.compilationUnit (GeneratedJavaRecognizer.java:202)
at com.puppycrawl.tools.checkstyle.JavaParser.parse (JavaParser.java:99)
at com.puppycrawl.tools.checkstyle.TreeWalker.processFiltered (TreeWalker.java:159)
at com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck.process (AbstractFileSetCheck.java:85)
at com.puppycrawl.tools.checkstyle.Checker.processFile (Checker.java:329)
at com.puppycrawl.tools.checkstyle.Checker.processFiles (Checker.java:291)
at com.puppycrawl.tools.checkstyle.Checker.process (Checker.java:216)
at org.apache.maven.plugins.checkstyle.exec.DefaultCheckstyleExecutor.executeCheckstyle (DefaultCheckstyleExecutor.java:202)
at org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo.execute (CheckstyleViolationCheckMojo.java:545)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) …
Run Code Online (Sandbox Code Playgroud)我正在尝试通过这样做来使用 checkstyle 和 findbugsmvn checkstyle:checkstyle
但我有这个错误
这个错误
[ERROR] Failed to execute goal on project my-project: Could not resolve dependencies for project default:my-project:jar:1.1: Could not find artifact com.sun:tools:jar:0 at specified path C:\Program Files\Java\jdk-11.0.2/../lib/tools.jar -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
我的 JDK 中没有 tools.jar(我有 jdk-11.0.2)。
我从 2H 开始使用它,请帮助:/
我正在寻找配置 google_checks 以4 spaces
在 Maven Checkstyle 插件中使用的方法。我将indentSize
配置参数设置为4,但是不起作用。有配置选项来设置这个吗?我不想拥有自己的版本,google_checks.xml
只是缩进 4 个空格。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<dependency>
<artifactId>checkstyle</artifactId>
<groupId>com.puppycrawl.tools</groupId>
<version>8.36.1</version>
</dependency>
</dependencies>
<configuration>
<configLocation>google_checks.xml</configLocation>
<indentSize>4</indentSize>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
更新:似乎没有办法有一个与maven-checkstyle-plugin
,Checkstyle with google_checks
和兼容的单一格式Intellij with google_java_format
。有人能够实现这一目标吗?
尝试清理我的 时${project.build.directory}
,我注意到maven-checkstyle-plugin
将三个文件放入我的target
文件夹中:checkstyle-checker.xml
、checkstyle-cachefile
和checkstyle-result.xml
。
我能够将最后两个重定向到他们自己的文件夹中target/checkstyle
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<cacheFile default-value="${project.build.directory}/checkstyle/checkstyle-cachefile"/>
<configLocation>google_checks.xml</configLocation>
[...]
<outputFile default-value="${project.build.directory}/checkstyle/checkstyle-result.xml">${checkstyle.output.file}</outputFile>
</configuration>
[...]
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我能找到的所有内容都checkstyle-checker
在propertiesLocation下。有说:
如果成功解析,属性位置的内容将被复制到 ${project.build.directory}/checkstyle-checker.properties 文件中,然后传递给 Checkstyle 进行加载。
我可以更改属性位置内容复制到的位置吗?或者是否有另一种方法可以使插件将checkstyle-checker.xml
文件写入我的自定义文件夹target/checkstyle
?
我有一个maven的java应用程序具有以下结构:
parent
| - pom.xml
| - child
| - pom.xml
| - analyzers
| - pmdrules.xml
| - checkstyle.xml
Run Code Online (Sandbox Code Playgroud)
我在父pom.xml中配置了PMD和checkstyle.对于PMD,规则集配置如下,它对父模块和子模块都可以正常工作:
<configuration>
<rulesets>
<ruleset>${basedir}/../analyzers/pmdrules.xml</ruleset>
</rulesets>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但是,对于checkstyle,如果我以相同的方式配置configLocation,它在父节点或子节点中都会失败.我必须使用自定义属性来克服这个问题.
<configuration>
<!-- Below config with ${projectRootDir}, a custom property always pointing to parent root works fine -->
<configLocation>${projectRootDir}/analyzers/checkstyle.xml</configLocation>
<!-- Below configurations with ${basedir} will fail build for child -->
<!--<configLocation>${basedir}/analyzers/checkstyle.xml</configLocation>-->
<!-- Below configurations with ${basedir} will fail build for parent -->
<!--<configLocation>${basedir}/../analyzers/checkstyle.xml</configLocation>-->
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是一个复制器样本 - https://github.com/ramtech123/pocs/blob/master/myapp-parent-module/pom.xml
我尝试在调试模式下运行maven构建.从日志中,对我而言,实际的PMD执行似乎仅针对子模块进行,因此它没有问题.
有人可以帮我理解根本原因,并改善我的配置.
提前致谢.
大多数情况下只是出于好奇,但如果您在 Maven 项目上使用 checkstyle 配置文件和checkstyle.xml
(单独的)抑制文件,并且您希望使用 CheckStyle- 将这些 checkstyle 配置导入到 IntelliJ 中的代码样式中IDEA 插件,您可以这样做(例如,请参阅checkstyle 配置中的 IntelliJ IDEA 代码格式) - 但是对此代码样式的抑制又如何呢?在 IntelliJ 中设置代码样式时,您只能从一个文件(当然是)导入配置。如果您在使用(例如,标签)中正确指定了抑制,那么此代码样式是否“知道”抑制?它需要了解镇压吗?checkstyle-suppressions.xml
maven-checkstyle-plugin
checkstyle.xml
pom.xml
<suppressionsLocation>
code-formatting intellij-idea checkstyle maven-checkstyle-plugin
maven ×8
checkstyle ×7
java ×6
findbugs ×1
java-9 ×1
maven-plugin ×1
pmd ×1
sonarqube ×1
spotless ×1