使用 Maven 和 JDK 11 的声纳扫描仪

Posted

技术标签:

【中文标题】使用 Maven 和 JDK 11 的声纳扫描仪【英文标题】:Sonar scanner with Maven and JDK 11 【发布时间】:2019-03-09 03:39:20 【问题描述】:

我可以让 Sonar 扫描仪与 OpenJDK 8 一起工作,但不能与 OpenJDK 11 一起工作。

使用的Maven命令是:

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.report.export.path=sonar-report.json -P ci

构建失败:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project framework-bio: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar failed: A required class was missing while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar: javax/xml/bind/ValidationEventHandler
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.codehaus.mojo:sonar-maven-plugin:3.4.0.905
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/var/lib/jenkins/.m2/repository/org/sonarsource/scanner/maven/sonar-maven-plugin/3.4.0.905/sonar-maven-plugin-3.4.0.905.jar
[ERROR] urls[1] = file:/var/lib/jenkins/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.4/plexus-sec-dispatcher-1.4.jar
[ERROR] urls[2] = file:/var/lib/jenkins/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
[ERROR] urls[3] = file:/var/lib/jenkins/.m2/repository/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar
[ERROR] urls[4] = file:/var/lib/jenkins/.m2/repository/org/sonarsource/scanner/api/sonar-scanner-api/2.10.0.1189/sonar-scanner-api-2.10.0.1189.jar
[ERROR] urls[5] = file:/var/lib/jenkins/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: javax.xml.bind.ValidationEventHandler
[ERROR] -> [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/PluginContainerException

Sonar Scanner 是否有望与 JDK 11 一起使用?

【问题讨论】:

或者你可以将explicitly added the javax.xml.bind:jaxb-api添加到你的依赖项中? 确实如此。但是我不喜欢仅仅因为它的代码分析器错过它而向我的项目添加依赖项的想法。 好吧,除非你最终意识到这个类对你的项目很重要......如果不是,它不应该放在第一位: ) 我不确定您的评论是否理解。我 100% 确定我的项目不需要 javax.xml.bind:jaxb-api,只有 Sonar 扫描仪下载的插件才需要。 @nullpointer 该模块在 JDK11 中不再存在 【参考方案1】:

终于找到https://github.com/sonargraph/sonar-sonargraph-integration/issues/14

问题来自名为 sonar-sonargraph-integration 的 SonarQube 插件。 我从 SonarQube 服务器上卸载了插件,问题就消失了。

【讨论】:

以上是关于使用 Maven 和 JDK 11 的声纳扫描仪的主要内容,如果未能解决你的问题,请参考以下文章

詹金斯 - sonarQube 问题 ||声纳扫描仪插件

如何通过非 maven 项目的声纳的 junit 测试来测量代码覆盖率

将 Jacoco 代码覆盖率发布到声纳的命令

声纳:在一个项目中索引了 0 个文件,在另一个项目中正确扫描

使用声纳扫描仪在我的反应项目中意外的令牌 =(在模块模式下使用 espree 解析器)

使用 .net 核心声纳扫描仪将声纳结果发布到 tfs 构建