我想执行一个 maven 目标,但是 checkstyle 错误禁止这样做。我现在没有时间纠正 checkstyle 错误(我的 checkstyle 规则最近已经更新了,我现在无法处理所有的错误)。
有没有办法禁用校验样式操作并执行我的目标呢?
解决方案是: mvn [target] -Dcheckstyle.skip。
mvn [target] -Dcheckstyle.skip
I like this solution as it is temporary and do not require editing of pom files, or anything that can be versioned.
如果您想要从 pom 中禁用 checkstyle,您可以将 checkstyle 插件添加到您的 pom 中,并将执行阶段设置为 none。对我来说重要的是我必须把 id 设置得和在 Pom 中完全一样。在其他情况下,它不工作。
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <executions> <execution> <id>checkstyle-validation</id> <phase>none</phase> </execution> </executions> </plugin>
随机编码器的答案是首选的。
If you want to disable checkstyle from your pom, you can add the checkstyle plugin to the pom and set the skip flag to prevent the check.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>
一句话:
<properties> <checkstyle.skip>true</checkstyle.skip> </properties>
所提供的解决方案是针对整个项目/模块的,但是我只需要跳过某个类的 checkstyle。所以我只是想分享我找到的解决方案。< br > 如果不想排除整个模块并且只排除一个特定的类,可以在 pom 中添加排除项,如下所示:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>3.1.1</version> <configuration> <excludes>path/to/your/class/from/sources/root/myclass.java</excludes> </configuration> </plugin>