[英]Can't configure Checkstyle in Maven multimodule project
I'm working with Java multimodule project in Eclipse. 我正在Eclipse中使用Java多模块项目。 And I have to configure Checkstyle to my Maven build and fail the build in case of any violations.
而且我必须将Checkstyle配置为我的Maven构建,并在发生任何违规的情况下使构建失败。 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.
我在此网站上找到了推荐使用本教程的建议: https : //maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html而且我决定遵循它。
I've added the new subfolder build-tools with my checkstyle.xml and made all changes in project's pom.xml 我已经用我的checkstyle.xml添加了新的子文件夹构建工具 ,并在项目的pom.xml中进行了所有更改。
Main pom.xml file 主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>
<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. 当我编写一些带有checkstyle违规的Java代码时, Maven安装会给我带来成功,但由于违规,我不得不使项目失败。 Where I go wrong?
我哪里出问题了? Maybe I wrote the wrong path to my checkstyle.xml?
也许我写了我的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
. 如果查看
com.softserveinc.ita:build-tools:1.0
的jar文件,将会看到没有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 . 另外,您应该安装/部署
com.softserveinc.ita:build-tools:1.0
如果工作区中有项目,Eclipse通常会为您解决此问题,但是我不确定此机制是否可以处理插件的依赖项。
Moreover, it sounds as if you want to fail the build during the <build>
lifecycle, as opposed to the <reporting>
lifecycle (site). 而且,听起来好像您想在
<build>
生命周期(而不是<reporting>
生命周期(站点))中使<build>
失败。 Check out the last section of https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html 查看https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html的最后一部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.