如何使用checkstyle停止maven构建 [英] how to stop maven build using checkstyle
问题描述
我是maven和checkstyle的新手所以请礼貌:)。
I am new to maven and checkstyle so please be polite:).
我已经设法使用maven和checkstyle插件,我可以创建我的代码报告。但我真正想要的是,如果样式检查有任何错误,我可以停止maven的构建过程。
I've managed to use maven with checkstyle plugin and I can create reports on my code. But what I want really to have is that I can stop the build process of maven if there are any errors on style check.
到目前为止,我的pom.xml如下所示:
So far my pom.xml looks like below:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
</project>
我如何才能达到目标?我们的团队希望拥有严格的编码风格标准,因此我必须使用它。
How can I reach my goal here? Our team wants to have strict coding style standards so I have to use it.
推荐答案
要实现您的目标,除了报告之外,还需要在构建生命周期中使用maven-checkstyle-plugin生命周期:
To achieve what you want, you need to use the maven-checkstyle-plugin in the build lifecycle in addition to the reporting lifecycle:
<project>
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<failsOnError>true</failsOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
这篇关于如何使用checkstyle停止maven构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!