Checkstyle Gradle

Checkstyle with Gradle

我正在尝试将 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'
}

但是出错了

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

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

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

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