I'm working with Java multimodule project in Eclipse. And I have to configure Checkstyle to my Maven build and fail the build in case of any violations. I've found the recomendation on this site to use this tutorial: https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html And I decided to follow by it.
I've added the new subfolder build-tools with my checkstyle.xml and made all changes in project's pom.xml
Main pom.xml file
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
<dependencies>
<dependency>
<groupId>com.softserveinc.ita</groupId>
<artifactId>build-tools</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.16</version>
<configuration>
<configLocation>build-tools/src/main/resources/jresume/checkstyle.xml</configLocation>
<headerLocation>build-tools/src/main/resources/jresume/LICENSE.txt</headerLocation>
<failsOnError>true</failsOnError>
</configuration>
</plugin>
</plugins>
</reporting>
<modules>
<module>common</module>
<module>persistence</module>
<module>business</module>
<module>logging</module>
<module>web</module>
<module>build-tools</module>
</modules>
</project>
When I write some java code with checkstyle violations Maven install gives me SUCCES but I have to fail the project because of violations. Where I go wrong? Maybe I wrote the wrong path to my checkstyle.xml? Help me please.
Change config to:
<configLocation>jresume/checkstyle.xml</configLocation>
<headerLocation>jresume/LICENSE.txt</headerLocation>
These parameters are relative to your source folder(s).
If you look in the jar file of com.softserveinc.ita:build-tools:1.0
, you will see that there is no src/main/resources
.
Also, you should install/deploy com.softserveinc.ita:build-tools:1.0
Eclipse would normally resolve this for you if you have project in the workspace, but I am unsure if this mechanism works with dependencies to plugins .
Moreover, it sounds as if you want to fail the build during the <build>
lifecycle, as opposed to the <reporting>
lifecycle (site). Check out the last section of https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.