2012-06-19 48 views
5

我一直在努力嘗試在Eclipse Indigo IDE中的Maven中使用Checkstyle工作一段時間。最後,我想我會請求一些專家建議。Maven Checkstyle:檢查不工作

我正在使用Eclipse Indigo並嘗試將Checkstyle配置爲在Maven中運行。

下面是我的pom.xml的一個片段。只有checkstlye:checkstlye正在工作並創建報告。

======

<profile> 
     <id>checkstyle-profile</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-checkstyle-plugin</artifactId> 
        <version>2.9.1</version> 
        <configuration> 
         <includeTestSourceDirectory>true</includeTestSourceDirectory> 
         <configLocation>${basedir}/src/main/resources/maven_checks.xml</configLocation> 
        </configuration> 
        <executions> 
         <execution> 
          <id>checkstyle-check</id> 
          <goals> 
           <goal>check</goal> 
          </goals> 
          <phase>compile</phase> <!-- Default is "verify" --> 
          <configuration> 
           <violationSeverity>error</violationSeverity> 
           <maxAllowedViolations>7000</maxAllowedViolations> 
           <failOnViolation>true</failOnViolation> 
           <failsOnError>true</failsOnError> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 

</profiles> 

<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-checkstyle-plugin</artifactId> 
      <version>2.9.1</version> 
      <configuration> 
       <configLocation>${basedir}/src/main/resources/maven_checks.xml</configLocation> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jxr-plugin</artifactId> 
      <version>2.3</version> 
     </plugin> 
    </plugins> 
</reporting>  

一些事情,沒有工作是:

  1. configLocation自定義checkstlye被忽略,且始終默認到Sun checkstlye。
  2. 我無法運行checkstlye:檢查。我得到以下錯誤。我應該運行什麼目標以便checkstyle:check運行。 無法執行目標org.apache.maven.plugins:項目zzz-web上的maven-checkstyle-plugin:2.9.1:check(default-cli):您有5950 Checkstyle衝突
  3. 配置設置是否適合失敗如果違規數量超過7000,構建?
  4. Checkstyle報表無法交叉引用報表中的Java代碼。因此,例如,如果我嘗試從包向下鑽取Java類,然後單擊違規的行號,則不會將我帶到Java文件。也許我沒有正確配置jxr插件。

希望快速回復。

在此先感謝。 Varma

回答

7

您有綁定check目標maven checkstyle plugincompile階段。在這種情況下,您需要運行mvn compile以使用您的配置。運行mvn checkstyle:check將使用默認配置。這看起來像上面第1項和第2項最可能的情況。

即使您運行mvn compile上述配置,因爲兩者都被設置爲true仍然會失敗是考慮到兩個配置項failOnViolationfailOnError的構建。只要違規數量少於7000,刪除這些條目並運行mvn compile應該通過構建。

+0

謝謝Raghuram!感謝你的幫助。 – AVarma

+2

@AVarma。當然,您可能想要upvote和/或[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),以便將來幫助他人。 – Raghuram

+0

報告問題/改進 - https://issues.apache.org/jira/browse/MCHECKSTYLE-314 –

0

1.config自定義checkstlye的位置被忽略,並且始終默認爲Sun checkstlye。

對於此,請使用以下標籤:>

<properties<checkstyle.config.location>properties/checkstyle.xml</checkstyle.config.location> </properties> 
在你的項目上,你的使用checkstyle.this線將在頂部和下方的pom.xml的標籤的pom.xml

<version>0.0.1-SNAPSHOT</version>