【问题标题】:Class 'XXX/XXX/XXX ' is not accessible through the ClassLoader warning in Sonar analysis with Jenkins build and maven project无法通过使用 Jenkins 构建和 maven 项目进行声纳分析中的 ClassLoader 警告访问类“XXX/XXX/XXX”
【发布时间】:2014-07-08 10:10:50
【问题描述】:

我知道这是一个反复出现的问题,但我找不到我的问题的解决方案。

JENKINS 中,我在构建后运行 SONAR 分析。当 Soanar 到达 Java bytecode scan... 时,它会显示:WARN - Class '.../.../.../...' is not accessible through the ClassLoader

扫描是在 Maven 项目上进行的,Sonar 在此消息中不断显示抛出许多其他使用 Maven 依赖项的类。

声纳分析使用SONAR-RUNNER

我在许多帖子中看到,可以通过在 sonar-project.properties 中添加 sonar.librairies=/path/to/libraries/*jar 来解决此问题,但使用 Maven 时,依赖项不会被归类到一个文件夹下。 Jar 被分发到 ma​​ven-repositories 下的不同文件夹中。

那么我该如何解决这个问题以在没有这些警告的情况下扫描我的代码?

仅供参考:

詹金斯 1.555

声纳 4.2

声纳亚军 2.3

Java 1.7

Maven 3.04

堆栈跟踪

09:23:55.605 INFO  - Java bytecode scan...
09:23:55.646 WARN  - Class 'org/springframework/context/ApplicationContext' is not    accessible through the ClassLoader.
09:23:55.656 WARN  - Class 'com/mongodb/MongoClient' is not accessible through the ClassLoader.
09:23:55.657 WARN  - Class 'com/mongodb/DB' is not accessible through the ClassLoader.
09:23:55.661 WARN  - Class 'org/springframework/context/ApplicationContext' is not    accessible through the ClassLoader.
09:23:55.662 WARN  - Class 'org/springframework/context/ApplicationContext' is not accessible through the ClassLoader.
...
09:23:55.749 WARN  - Class 'org/apache/log4j/Logger' is not accessible through the ClassLoader.
09:23:55.773 INFO  - Java bytecode scan done: 168 ms

编辑

在 jenkins 构建中运行 mvn dependency:tree

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli)
[INFO] +- org.springframework:spring-context:jar:4.0.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.0.3.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.0.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.0.3.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.0.3.RELEASE:test
[INFO] +- org.apache.poi:poi:jar:3.9:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.5:compile
...
...
[INFO] +- org.mockito:mockito-all:jar:1.9.5:test
[INFO] +- com.jayway.jsonpath:json-path:jar:0.9.1:test
[INFO] |  \- net.minidev:json-smart:jar:1.2:test
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] \- junit:junit:jar:4.11:test (scope not updated to compile)

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

谢谢

【问题讨论】:

  • 您有任何可能有帮助的堆栈跟踪吗?你在构建上运行什么 maven 命令?
  • 好了,我已经编辑了这篇文章。感谢您考虑我的帖子。
  • 您是否正在运行 mvn clean:install 作为命令?
  • 我将clean作为 maven 目标运行
  • mvn clean 只会清理你的项目缓存输出。您需要构建项目,因此我建议您将目标更改为“全新安装”

标签: java maven jenkins sonarqube sonar-runner


【解决方案1】:

由于 Maven 列出了缺失的类,您可能正在使用 Jenkins 插件来运行 Sonar。我从未使用过这个插件,但我的猜测是它不了解 Maven。因此,它无法从 POM 创建类路径,并且在运行时确实缺少类。

尝试使用 Maven 目标运行 Sonar:mvn sonar:sonarconfiguring the Sonar plugin for Maven correctly 之后。

【讨论】:

  • 嗨亚伦。现在我将声纳作为 Maven 目标运行,我解决了类依赖警告,但现在我看到声纳只分析 JAVA 代码,不再分析 JS。即使sonar.sources 设置为src\main 我有我的Java 和Js 代码。它似乎是我自己设置和选择的Maven ovveride source.sources sonar.sources=src/main/java。所以在简历中,如果我使用独立声纳分析,我不能拥有所有的依赖关系,当我使用声纳作为maven目标时,我只能分析JAVA。那该怎么办?
  • 我认为这是一个新问题。将它与 Jenkins 插件的配置和您在 POM 中使用的配置一起发布。应该有一种方法可以将 Maven 插件配置为与 Jenkins 插件执行相同的操作。
  • 好的。在这里完成:stackoverflow.com/questions/23915270/…
  • @Ismail Sen 我遇到了同样的问题。你是如何解决这个问题的?谢谢。
  • @Renren29 作为 Maven 目标运行声纳任务。这样,Sonar 将加载所有依赖项。默认情况下,将 Sonar 作为 Maven 目标运行将分析所有 /src 文件夹。如果您想指定 Sonar 应该分析的内容,请转到 pom.xml 并添加 <properties>...</properties> 这个:<sonar.sources>...</sonar.sources。对于测试源添加<sonar.tests>...</sonar.tests>。要查看在使用 Maven 运行 Sonar 时应在 pom.xml中设置的所有 Sonar 属性,请在此处查看:jira.codehaus.org/browse/MSONAR-70
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
  • 2023-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-24
相关资源
最近更新 更多