【问题标题】:Can't configure Checkstyle in Maven multimodule project无法在 Maven 多模块项目中配置 Checkstyle
【发布时间】:2015-12-02 21:08:52
【问题描述】:

我正在 Eclipse 中使用 Java 多模块项目。而且我必须为我的 Maven 构建配置 Checkstyle,并在出现任何违规时使构建失败。 我在这个网站上找到了使用本教程的推荐:https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html 我决定遵循它。

我已将新的子文件夹 build-tools 添加到我的 checkstyle.xml 中,并对项目的 pom.xml 进行了所有更改

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>

当我编写一些带有 checkstyle 违规的 java 代码时,Maven install 给了我成功,但我不得不因为违规而使项目失败。我哪里错了?也许我给我的 checkstyle.xml 写了错误的路径?请帮帮我。

【问题讨论】:

    标签: java xml eclipse maven checkstyle


    【解决方案1】:

    将配置更改为:

        <configLocation>jresume/checkstyle.xml</configLocation>
        <headerLocation>jresume/LICENSE.txt</headerLocation>
    

    这些参数与您的源文件夹相关。

    如果你查看com.softserveinc.ita:build-tools:1.0的jar文件,你会看到没有src/main/resources

    另外,如果您在工作区中有项目,您应该安装/部署com.softserveinc.ita:build-tools:1.0 Eclipse 通常会为您解决此问题,但我不确定此机制是否适用于 插件 的依赖项。 p>

    此外,听起来好像您想在 &lt;build&gt; 生命周期中失败构建,而不是 &lt;reporting&gt; 生命周期(站点)。查看https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html的最后一段

    【讨论】:

      猜你喜欢
      • 2012-04-16
      • 2017-09-21
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      • 2016-04-28
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多