2012-09-20 64 views
2

我正在使用Maven
我有一個父模塊和一些其他模塊。他們看起來像:如何在maven中配置checkstyle?

 
PARENT 
├── pom.xml 
├── ModulA 
| └── pom.xml 
└── ModulB 
    ├── pom.xml 
    └── folder 
     └── checkstyle.xml 

我試圖用我自己的規則來替換規則。但它忽略了我的規則。我加入了插件父pom.xml的

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-checkstyle-plugin</artifactId> 
    <version>2.9.1</version> 
    <configuration> 
     <includeTestSourceDirectory>true</includeTestSourceDirectory> 
     <configLocation> 
      ${basedir}/../ModulB/folder/checkstyle.xml     
     </configLocation> 
    </configuration> 
</plugin> 

問題出在哪裏?

編輯:


MVN的CheckStyle:CheckStyle的-X

... 
    <configuration> 
     <cacheFile default-value="${project.build.directory}/checkstyle-cachefile"/> 
     <configLocation default-value="config/sun_checks.xml">${checkstyle.config.location}</configLocation> 
     <consoleOutput default-value="false"/> 
     <enableFilesSummary default-value="true">${checkstyle.enable.files.summary}</enableFilesSummary> 
     <enableRSS default-value="true">${checkstyle.enable.rss}</enableRSS> 
     <enableRulesSummary default-value="true">${checkstyle.enable.rules.summary}</enableRulesSummary> 
     <enableSeveritySummary default-value="true">${checkstyle.enable.severity.summary}</enableSeveritySummary> 
     <encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding> 
     <excludes>${checkstyle.excludes}</excludes> 
     <failsOnError default-value="false"/> 
     <format default-value="sun"/> 
     <headerFile>${basedir}/LICENSE.txt</headerFile> 
     <headerLocation default-value="LICENSE.txt">${checkstyle.header.file}</headerLocation> 
     <includeTestSourceDirectory default-value="${false}"/> 
     <includes default-value="**/*.java">${checkstyle.includes}</includes> 
     <linkXRef default-value="true">${linkXRef}</linkXRef> 
     <outputDirectory default-value="${project.reporting.outputDirectory}"/> 
     <outputFile default-value="${project.build.directory}/checkstyle-result.xml">${checkstyle.output.file}</outputFile> 
     <outputFileFormat default-value="xml">${checkstyle.output.format}</outputFileFormat> 
     <project default-value="${project}"/> 
     <propertiesLocation>${checkstyle.properties.location}</propertiesLocation> 
     <skip default-value="false">${checkstyle.skip}</skip> 
     <sourceDirectory default-value="${project.build.sourceDirectory}"/> 
     <suppressionsFileExpression default-value="checkstyle.suppressions.file">${checkstyle.suppression.expression}</suppressionsFileExpression> 
     <suppressionsLocation>${checkstyle.suppressions.location}</suppressionsLocation> 
     <testSourceDirectory default-value="${project.build.testSourceDirectory}"/> 
     <xrefLocation default-value="${project.reporting.outputDirectory}/xref"/> 
    </configuration> 
... 
+0

瓦它是否忽略了你的規則:mvn checkstyle:checktyle還是你的IDE?在所有模塊上? – yodamad

+0

@yodamad是的,在所有模塊上.. – Kayser

+0

@yodamad我不知道如何寫入checkstyle.xml的路徑 – Kayser

回答

4

爲什麼你不把你的CheckStyle配置在目錄中父項目就像src/main/resources和參數化插件中像這樣的父pom.xml

<!-- Checkstyle --> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-checkstyle-plugin</artifactId> 
    <version>RELEASE</version> 
    <configuration> 
     <configLocation>src/main/resources/checkstyle.xml</configLocation>     
    </configuration> 
</plugin> 

名兒童的項目應該有機會做這個配置

+0

這是項目結構。所有的配置文件都在ModulB – Kayser

+1

好吧,所以你可以試試這個變量'$ {project.parent.basedir}'而不是'$ {basedir}' – yodamad

+0

我在src /在父模塊中複製。這是行不通的。 :-( – Kayser

11

對於它拿起您的自定義配置,你需要聲明的文件作爲一個屬性:

<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"> 
    ... 

    <properties> 
    <checkstyle.config.location><!-- file location --></checkstyle.config.location> 
    </properties> 

    <build> 
    ... 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-checkstyle-plugin</artifactId> 
     <version>2.9.1</version> 
     </plugin> 
    </plugins> 
    </build> 

</project> 

從我的教程兩者如何創建自定義的CheckStyle點擊這裏:
http://blog.blundellapps.com/create-your-own-checkstyle-check/

源代碼在這裏:
https://github.com/blundell/CreateYourOwnCheckStyleCheck

+2

你是對的。官方文檔在http://maven.apache.org/plugins/maven-checkstyle-plugin/和http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/custom-checker-config。html說你需要使用configLocation參數來配置它,但這對我不起作用,而設置屬性很好。謝謝。 –

+0

當我終於意識到@GlennLawrence是真的時,我正在拉我的頭髮! – gustavohenke

相關問題