2015-10-19 33 views
1

我想將Checkstyle規則引入到Gradle項目中,即存儲庫中的任何文件都不能包含製表符,包括源集之外的文件(例如README.md)。在所有項目文件上使用Gradle運行Checkstyle

我試着用下面的配置:

apply plugin: 'java' 
apply plugin: 'checkstyle' 

checkstyle { 
    checkstyleMain.source = '.' 
} 

但後來我得到異常:

Failed to capture snapshot of input files for task 'checkstyleMain' during up-to-date check. See stacktrace for details. 
Failed to create MD5 hash for file .gradle\2.7\taskArtifacts\cache.properties.lock. 

這意味着,我需要排除.gradle目錄,並極有可能其他人一樣.git.idea ,但我該怎麼做?

+0

確定checkstyle可以針對非java文件運行嗎? – Ethan

+0

是的 - 你甚至在Checker中有'fileExtensions'屬性:http://checkstyle.sourceforge.net/config.html#Checker –

+0

我會創建一個fileTree,然後排除你不想包含的目錄。 – Ethan

回答

0

這是適合我的解決方案。它分析項目中除.git.idea,gradle,build和其他IntelliJ IDEA或Gradle特定自動生成文件之外的所有文件。

apply plugin: 'java' 
apply plugin: 'checkstyle' 

checkstyle { 
    toolVersion = '6.12.1' 
} 

checkstyleMain { 
    source = fileTree('.') { 
     excludes = ['.*/**', 'gradle*', 'build/**', '*.iml', '*.log', '**/*.jar'] 
    } 
} 
相關問題