0
votes

I'm trying to switch from the default checkstyle configuration, sun-checks, to google-checks.

In my jenkinsfile, I'm writing:

   stage('checkstyle') {
            steps {
                sh "mvn clean checkstyle:checkstyle -Dcheckstyle.config.location='https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml'"
                checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: 'target/checkstyle-result.xml', unHealthy: ''
            }
        }

This is failing with the error message

Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle (default-cli) on project pmm: An error has occurred in Checkstyle report generation.: Failed during checkstyle execution: Failed during checkstyle configuration: unable to parse configuration stream - Element type "html" must be declared.:8:17 -> [Help 1]

How can I change the checkstyle configuration for Jenkins?

1

1 Answers

2
votes

https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml

First, you are giving it an HTML document not the XML file. You must use the URL to github's raw file.

Example: https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml

Secondly, you shouldn't use the online SNAPSHOT version of google_checks. See https://stackoverflow.com/a/44060396/1016482 to understand why.

How can I change the checkstyle configuration for Jenkins?

Extract the configuration found in the checkstyle JAR (if your going to change it), and have your maven command use that instead.