在我的Gradle项目中,我使用google_checks.xml作为CheckStyle配置。
我需要能够在我的一个类中禁用MemberName警告,并且我可以使用@SuppressWarnings("checkstyle:MemberName")来实现这一点,当且仅当我将SuppressWarningsHolder和SuppressWarningsFilter添加到google_checks.xml / 这个职位中。
问题是我定期更新google_checks.xml,我不想记住需要重新添加这些内容,所以我想在一个单独的checkstyle-suppressions.xml文件中处理这些抑制。这对于google_checks.xml的这一部分应该是可行的。
<module name="SuppressionFilter">
<property default="checkstyle-suppressions.xml" name="file"
value="${org.checkstyle.google.suppressionfilter.config}"/>
<property name="optional" value="true"/>
</module>但是,我不知道如何让它在我的项目的根目录中而不是在默认的.gradle\daemon\6.5.1\checkstyle-suppressions.xml路径中查找这个文件。我怎么才能把它指向别的地方呢?
如果我设置了value="${config_loc}/checkstyle-suppressions.xml",它会做我想做的事情,但是我们又回到了我不想修改google_style.xml的问题上。
我似乎需要以某种方式设置org.checkstyle.google.suppressionfilter.config系统属性,但我不知道在我的Gradle配置文件中应该在哪里进行设置,也不知道应该将其设置为什么。
发布于 2020-11-05 18:53:05
由于它是一个系统属性,您可以按照下面的配置在build.gradle中重写它,比如在项目根文件夹中有checkstyle-suppressions.xml。
注意:配置文件指向来自校验样式jar的google_checks.xml,而不是项目的一部分。
System.setProperty( "org.checkstyle.google.suppressionfilter.config", project.projectDir.toString()+"/checkstyle-suppressions.xml" )
checkstyle {
toolVersion = checkStyleVersion
configFile = file("/google_checks.xml")
ignoreFailures = false
showViolations = false
maxWarnings = 0
}发布于 2021-10-20 16:48:16
Gradle插件为此提供了Map configProperties选项。
可在配置文件中使用的属性。它们被替换到配置文件中。
所以对于suppressions.xml文件夹中的.checkstyle,
checkstyle {
configProperties = [
"org.checkstyle.google.suppressionfilter.config":
"${projectDir}/.checkstyle/suppressions.xml",
]
}https://stackoverflow.com/questions/62989823
复制相似问题