Java 通过Checkstyle-suppressions.xml抑制Google Checkstyle警告

Java 通过Checkstyle-suppressions.xml抑制Google Checkstyle警告,java,gradle,checkstyle,Java,Gradle,Checkstyle,我在Gradle项目中用作CheckStyle配置 我需要能够在我的一个类中抑制MemberName警告,并且我可以使用@SuppressWarnings(“checkstyle:MemberName”)当且仅当我将suppressWarningHolder和SuppressWarningsFilter添加到google\u checks.xml 是的 问题是我定期更新google_checks.xml,我不想记得需要重新添加这些,所以我想在一个单独的checkstyle suppression

我在Gradle项目中用作CheckStyle配置

我需要能够在我的一个类中抑制
MemberName
警告,并且我可以使用
@SuppressWarnings(“checkstyle:MemberName”)
当且仅当我将
suppressWarningHolder
SuppressWarningsFilter
添加到
google\u checks.xml
是的

问题是我定期更新
google_checks.xml
,我不想记得需要重新添加这些,所以我想在一个单独的
checkstyle suppressions.xml
文件中处理这些抑制。根据
google\u 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\u loc}/checkstyle suppressions.xml”
,它会执行我想要的操作,但我们又回到了我不想修改
google\u style.xml
的问题


似乎我需要以某种方式设置
org.checkstyle.google.suppressionfilter.config
系统属性,但我不确定在我的Gradle配置文件中执行此操作的位置,或者确切地将其设置为什么。

作为系统属性,您可以在
build.Gradle
中根据下面的配置覆盖它,假设您在项目根文件夹中有
checkstyle suppressions.xml

注意:配置文件指向checkstyle jar中的google_checks.xml,它不是项目的一部分


我认为SystemProperty的正确格式是
System.setProperty(“org.checkstyle.google.suppressionfilter.config”,“$rootProject.projectDir/checkstyle suppressions.xml”)
它可以双向工作,您也可以按照建议使用字符串插值。应根据其单个或多个项目生成使用对象项目或根项目。谢谢!最后使用:
System.setProperty(“org.checkstyle.google.suppressionfilter.config”,“$projectDir/config/checkstyle/checkstyle suppressions.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
}