Skip to content

Suppressing Google Checkstyle warnings via checkstyle-suppressions.xml

I’m using google_checks.xml as a CheckStyle config in my Gradle project.

I need to be able to suppress the MemberName warning in one of my classes, and I can do so using @SuppressWarnings("checkstyle:MemberName") if and only if I add SuppressWarningsHolder and SuppressWarningsFilter to google_checks.xml per this post.

The problem is that I update google_checks.xml regularly, and I don’t want to remember to need to re-add these, so I’d like to handle these suppressions in a separate checkstyle-suppressions.xml file. This should be doable per this section of google_checks.xml:

  <module name="SuppressionFilter">
    <property default="checkstyle-suppressions.xml" name="file"
    <property name="optional" value="true"/>

However, I can’t figure out how to get it to look for this file in my project’s root directory instead of in the default .gradledaemon6.5.1checkstyle-suppressions.xml path. How can I point it to another location?

If I set value="${config_loc}/checkstyle-suppressions.xml", it does what I want, but we’re back to the problem of me not wanting to have to modify google_style.xml.

It seems like I need to set the system property somehow, but I’m not sure where to do this in my Gradle config files, or what exactly to set it to.



As its a system property, you can override it in the build.gradle as per below config, say you have checkstyle-suppressions.xml in the project root folder.

NOTE: The config file is pointing to google_checks.xml from the checkstyle jar, and is not part of your project.

System.setProperty( "", project.projectDir.toString()+"/checkstyle-suppressions.xml" )
checkstyle {
    toolVersion = checkStyleVersion
    configFile = file("/google_checks.xml")
    ignoreFailures = false
    showViolations = false
    maxWarnings = 0
User contributions licensed under: CC BY-SA
7 People found this is helpful