gpt4 book ai didi

java - Maven 项目中的 Checkstyle。不能在违规的情况下使项目失败

转载 作者:搜寻专家 更新时间:2023-11-01 01:50:55 26 4
gpt4 key购买 nike

我对 Java 的 Checkstyle 插件有疑问。如果有任何违规行为,我需要让整个多模块项目失败。在父 pom.xml 我有以下内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ss.ita</groupId>
<artifactId>jresume</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>JResume</name>

<modules>
<module>common</module>
<module>persistence</module>
<module>business</module>
<module>logging</module>
<module>web</module>
</modules>
<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>dev/checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>
</project>

我的 checkstyle.xml 放在 dev 文件夹中。

当我运行我的项目时

mvn clean install

它打印所有违规的列表。但它不能使整个项目失败。它为所有模块打印成功。我尝试同时使用 failsOnErrorfailOnViolation。但它没有用。 In plugin documentation 有这些要求:

  • 需要执行 Maven 项目。
  • 需要解决范围内 Artifact 的依赖关系:测试。
  • 目标是线程安全的并支持并行构建。
  • 默认绑定(bind)到生命周期阶段:验证。

我哪里出错了。也许我以错误的方式编写了我的 pom.xml。请帮我解决这个问题。

最佳答案

可能你忘记了

<configuration>
...
<violationSeverity>warning</violationSeverity>
...
</configuration>

violationSeverity:被视为违规的最低严重性级别。有效值为“错误”、“警告”和“信息”。

默认值为error,表示warning不会使maven构建失败。

查看更多详细信息:

http://maven.apache.org/plugins/maven-checkstyle-plugin/check-mojo.html#violationSeverity

关于java - Maven 项目中的 Checkstyle。不能在违规的情况下使项目失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32461501/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com