简体   繁体   English

如何在Jenkins中为Java配置Checkstyle配置

[英]How to Configure a Checkstyle Configuration for Java in Jenkins

I'm trying to switch from the default checkstyle configuration, sun-checks, to google-checks. 我正在尝试从默认的checkstyle配置(sun-checks)切换到google-checks。

In my jenkinsfile, I'm writing: 在我的jenkinsfile中,我正在写:

   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] 无法在项目pmm上执行目标org.apache.maven.plugins:maven-checkstyle-plugin:2.17:checkstyle(default-cli):Checkstyle报告生成中发生错误。:checkstyle执行期间失败:checkstyle配置期间失败:无法解析配置流-必须声明元素类型“ html”。:8:17-> [帮助1]

How can I change the checkstyle configuration for Jenkins? 如何更改Jenkins的checkstyle配置?

https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml 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. 首先,给它一个HTML文档而不是XML文件。 You must use the URL to github's raw file. 您必须使用github 原始文件的URL。

Example: https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/main/resources/google_checks.xml 示例: 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. 其次,您不应该使用google_checks的在线SNAPSHOT版本。 See https://stackoverflow.com/a/44060396/1016482 to understand why. 请参阅https://stackoverflow.com/a/44060396/1016482了解原因。

How can I change the checkstyle configuration for Jenkins? 如何更改Jenkins的checkstyle配置?

Extract the configuration found in the checkstyle JAR (if your going to change it), and have your maven command use that instead. 提取在checkstyle JAR中找到的配置(如果要更改它),然后让您的maven命令使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM