与Gradle的Checkstyle

时间:2017-06-14 18:06:31

标签: gradle checkstyle

我正在尝试将checkstyle添加到build.gradle

Checkstyle模板属于commons-math3,可以从here访问。

但是这个文件使用${checkstyle.header.file}来检查每个源文件顶部的许可证声明。

<!-- Verify that EVERY source file has the appropriate license -->
<module name="Header">
  <property name="headerFile" value="${checkstyle.header.file}"/>
</module>

所以我在build.gradle中添加了以下短语:

checkstyle {
    configFile = rootProject.file("commons-math-checkstyle.xml")
    headerFile = rootProject.file("license-header.txt")
    toolVersion = '7.8.1'
}

但它出错了。

headerFile = rootProject.file("license-header.txt")删除build.gradle并在checkstyle xml文件中生成Header模块由<!---->包裹(即禁用)使checkstyle运行良好。

如何在checkstyle.header.file文件中声明build.gradle

1 个答案:

答案 0 :(得分:1)

您需要在Gradle文件中定义属性:

checkstyle {
    toolVersion '7.8.1';
    configFile file('commons-math-checkstyle.xml');
    configProperties 'checkstyle.header.file': file('license-header.txt');
}