2014-10-30 40 views
2

我正在用Gradle構建一個Java項目。我想分開任務:如何使用Gradle爲測試代碼和生產代碼指定不同的(PMD,Checkstyle,Findbugs)規則集?

我想對生產代碼 使用嚴格規則(即PMD,Checkstyle,Findbugs)以及更寬鬆的規則(即允許重複的字符串和幻數)進行測試。

我以前用螞蟻做過這個(很簡單),即使我知道我可以從Gradle調用ant任務,但我寧願使用相應的插件。

我怎麼去呢?

對於PMD我當前構建腳本如下:

apply plugin: 'pmd' 
pmd { 
    ignoreFailures = true 
    ruleSetFiles = files("$staticAnalysisCfgDir/pmd/pmdruleset.xml") 
    toolVersion = '5.1.3' 
    sourceSets = [sourceSets.main, sourceSets.test] 
} 

回答

2

而不是在pmd擴展配置規則集,對pmdMainpmdTest任務(相同的語法)配置。同樣適用於Checkstyle和FindBugs。

+0

我在發佈問題之前試過,但沒有奏效。現在我再次嘗試,而沒有指定'sourceSets' =>它的工作原理! – 2014-10-31 11:08:27

+0

'sourceSets'僅在'pmd'擴展中可用。它有效地確定'pmdMain','pmdTest'等中的哪一個將作爲'gradle build'的一部分運行。有關API的詳細信息,請查看[Gradle Build Language Reference](http://gradle.org/docs/current/dsl/index.html)。 – 2014-10-31 13:43:22

相關問題