2015-09-07 58 views
2

我正在使用Eclipse中的Java multimodule項目。而且我必須將Checkstyle配置到我的Maven構建中,並且在發生任何違規時都會使構建失敗。 我發現這個網站上的推薦使用這個教程:https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html我決定跟着它。無法在Maven多模塊項目中配置Checkstyle

我已經添加了新的子文件夾構建工具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> 

當我寫一些檢查式違規的java代碼Maven安裝給了我SUCCES但我必須失敗項目b由於違規行爲。我哪裏出錯了?也許我寫了錯誤的路徑到我的checkstyle.xml?請幫幫我。

回答

0

更改配置到:

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

這些參數是相對於你的源文件夾(S)。

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

此外,你應該安裝/部署com.softserveinc.ita:build-tools:1.0如果您在工作區項目的Eclipse通常會爲您解決問題,但我不能確定這是否機制依賴工程插件

此外,聽起來好像您要在<build>生命週期期間生成失敗,而不是<reporting>生命週期(站點)。查看https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html的最後一段