草庐IT

java - sonar-maven-plugin fails because of invalid checkstyle.xml (The processing instruction target matching "[xX][mM][lL]"is not allowed)

coder 2024-07-02 原文

我将 Maven 3.2.1 和 SonarQube 4.5 与 Checkstyle 5.6 结合使用。执行中

mvn sonar:sonar

对于某些项目工作正常,但其他项目失败并显示“无法执行 Checkstyle:无法读取 ... checkstyle.xml - 无法解析配置流 - 处理指令目标匹配”[xX][mM][lL] “不被允许”。这是输出:

### ~\.mavenrc
### Set JAVA_HOME for maven to /opt/Oracle_Java/jdk1.7.0_67
### Set MAVEN_OPTS to -Xmx512m -XX:MaxPermSize=512m

[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder    org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building cc4-common 4.14.10-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- sonar-maven-plugin:2.4:sonar (default-cli) @ cc4-common ---
[INFO] SonarQube version: 4.5
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-   common/target/sonar
INFO: SonarQube Server 4.5
[INFO] [13:09:54.973] Load global referentials...
[INFO] [13:09:55.122] Load global referentials done: 151 ms
[INFO] [13:09:55.134] User cache: /var/lib/jenkins/.sonar/cache
[INFO] [13:09:55.145] Install plugins
[INFO] [13:09:55.268] Install JDBC driver
[INFO] [13:09:55.278] Create JDBC datasource for jdbc:mysql://localhost:3306/sonar?   useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
[INFO] [13:09:57.034] Initializing Hibernate
[INFO] [13:09:58.837] Load project referentials...
[INFO] [13:09:59.766] Load project referentials done: 929 ms
[INFO] [13:09:59.766] Load project settings
[INFO] [13:10:00.806] Loading technical debt model...
[INFO] [13:10:00.838] Loading technical debt model done: 32 ms
[INFO] [13:10:00.843] Apply project exclusions
[INFO] [13:10:01.201] -------------  Scan cc4-common
[INFO] [13:10:01.206] Load module settings
[INFO] [13:10:02.293] Loading rules...
[INFO] [13:10:02.888] Loading rules done: 595 ms
[INFO] [13:10:02.907] Configure Maven plugins
[INFO] [13:10:03.161] Compare to previous analysis (2014-10-06)
[INFO] [13:10:03.217] Compare over 30 days (2014-09-13, analysis of 2014-09-13    02:44:12.0)
[INFO] [13:10:03.237] Compare to previous version (2014-07-16)
[INFO] [13:10:03.238] No quality gate is configured.
[INFO] [13:10:03.366] Initializer FindbugsMavenInitializer...
[INFO] [13:10:03.367] Initializer FindbugsMavenInitializer done: 1 ms
[INFO] [13:10:03.367] Base dir: /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-   common
[INFO] [13:10:03.367] Working dir: /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-common/target/sonar
[INFO] [13:10:03.368] Source paths: pom.xml, src/main/java
[INFO] [13:10:03.368] Test paths: src/test/java
[INFO] [13:10:03.368] Binary dirs: target/classes
[INFO] [13:10:03.368] Source encoding: UTF-8, default locale: en_US
[INFO] [13:10:03.368] Index files
[INFO] [13:10:03.378] Excluded sources: 
[INFO] [13:10:03.378]   **/package-info.java
[INFO] [13:10:04.074] 431 files indexed
[INFO] [13:10:08.941] Quality profile for java: SE-Tools 3.2 (with Findbugs)
[INFO] [13:10:09.281] Sensor JavaSquidSensor...
[INFO] [13:10:09.429] Java Main Files AST scan...
[INFO] [13:10:09.434] 273 source files to be analyzed
[ERROR] [13:10:09.873] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:09.891] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:09.934] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:10.134] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:10.267] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:10.296] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:10.778] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.121] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.452] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.491] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:11.515] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:11.574] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.576] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:11.632] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.658] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.690] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:11.699] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:12.654] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:12.668] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:12.687] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:12.712] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:13.052] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.089] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.140] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.182] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.307] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.349] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.375] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.393] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:13.466] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.425] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.475] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.501] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.516] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:15.533] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.538] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:15.577] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:15.591] Class not found: org.apache.commons.logging.Log
[ERROR] [13:10:15.604] Class not found: org.slf4j.impl.StaticLoggerBinder
[ERROR] [13:10:15.613] Class not found: org.apache.commons.logging.Log
[INFO] [13:10:15.615] 273/273 source files analyzed
[INFO] [13:10:15.666] Java Main Files AST scan done: 6237 ms
[INFO] [13:10:15.672] Java bytecode scan...
[INFO] [13:10:16.374] Java bytecode scan done: 702 ms
[INFO] [13:10:16.375] Java Test Files AST scan...
[INFO] [13:10:16.375] 158 source files to be analyzed
[INFO] [13:10:17.124] 158/158 source files analyzed
[INFO] [13:10:17.124] Java Test Files AST scan done: 749 ms
[INFO] [13:10:17.182] Package design analysis...
[INFO] [13:10:17.414] Package design analysis done: 232 ms
[INFO] [13:10:18.041] Sensor JavaSquidSensor done: 8759 ms
[INFO] [13:10:18.045] Sensor QProfileSensor...
[INFO] [13:10:18.049] Sensor QProfileSensor done: 4 ms
[INFO] [13:10:18.049] Sensor FindbugsSensor...
[INFO] [13:10:18.061] Execute Findbugs 3.0.0...
[INFO] [13:10:19.885] Findbugs output report: /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-common/target/sonar/findbugs-result.xml
[INFO] [13:10:41.963] Execute Findbugs 3.0.0 done: 23902 ms
[INFO] [13:10:42.008] Sensor FindbugsSensor done: 23959 ms
[INFO] [13:10:42.008] Sensor CheckstyleSensor...
[INFO] [13:10:42.017] Execute Checkstyle 5.6...
[INFO] [13:10:42.042] Checkstyle configuration: /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-common/target/sonar/checkstyle.xml
[ERROR] Can not execute Checkstyle
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 48.949 s
[INFO] Finished at: 2014-10-13T13:10:42+01:00
[INFO] Final Memory: 22M/286M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.4:sonar (default-cli) on project cc4-common: Can not execute Checkstyle: unable to read /srv/build/jenkins/jobs/cc4-trunk/workspace/trunk/cc4-common/target/sonar/checkstyle.xml - unable to parse configuration stream - The processing instruction target matching "[xX][mM][lL]" is not allowed.:1:223 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

其实生成的checkstyle.xml是错误的,因为它包含两次“<><>

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"><!-- Generated by Sonar --><module name="Checker"><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<!--
    This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
    Checkstyle-Configuration: CheckStyle configuration from the Maven parent
    Description: none
-->
<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
...

为了分析,我上传了这个文件: - checkstyle.xml:https://dl.dropboxusercontent.com/u/54665247/checkstyle.xml

在谷歌搜索中我一无所获。 有人可以帮我解决这个问题吗?

最佳答案

我解决了我的问题。似乎旧的、迁移的数据导致了这个问题:我使用 Sonar 已经好几年了,从 3.1 版开始。每隔一段时间我就会升级到当前版本,从而迁移我现有的 Sonar MySql 数据库。最后一次升级是从 3.7.4 到 4.5。似乎最初导入的 checkstyle.xml(引用 http://www.puppycrawl.com/dtds/configuration_1_3.dtd)的 XML header 被添加到当前 XML header (引用“http://www.puppycrawl.com/dtds/configuration_1_2.dtd”),但没有被替换,导致两个 XML header ,因此 XML 无效。

我通过删除 SonarQube 中受影响的项目解决了我的问题。此操作的代价是我丢失了过去几年的所有历史数据。

关于java - sonar-maven-plugin fails because of invalid checkstyle.xml (The processing instruction target matching "[xX][mM][lL]"is not allowed),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26339005/

有关java - sonar-maven-plugin fails because of invalid checkstyle.xml (The processing instruction target matching "[xX][mM][lL]"is not allowed)的更多相关文章

随机推荐