如果存在某些checkstyle错误,是否有可能以某种方式强迫Maven失败?现在,我必须运行site目标以生成javadocs和checkstyle报告。我想使其达到install目标,如果checkstyle出现错误,则需要构建才能失败。这有可能实现吗?
checkstyle
site
javadocs
install
现在我有checkstyle报告的Maven块:
<reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.9.1</version> <configuration> <configLocation>src/test/resources/checkstyle.xml</configLocation> </configuration> </plugin> </plugins> </reporting>
您需要绑定checkstyle:check到Maven生命周期阶段(例如validate)并设置failOnViolation为true。
checkstyle:check
failOnViolation
就像是:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.9.1</version> <executions> <execution> <id>checkstyle</id> <phase>validate</phase> <goals> <goal>check</goal> </goals> <configuration> <failOnViolation>true</failOnViolation> </configuration> </execution> </executions> </plugin>