课程' XXX / XXX / XXX'无法通过使用Jenkins构建和maven项目的Sonar分析中的ClassLoader警告访问

时间:2014-05-20 08:39:13

标签: java maven jenkins sonarqube sonar-runner

我知道它的重复性问题,但我无法找到解决问题的方法。

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

扫描位于 Maven 项目上,Sonar会在此消息中显示使用 Maven 依赖的许多其他类。

声纳分析正在使用 SONAR-RUNNER

我在很多帖子中看到,可以通过在sonar.librairies=/path/to/libraries/*jar中添加sonar-project.properties来解决问题,但在 Maven 中,依赖项不会归入一个文件夹。在 maven-repositories 下的不同文件夹下发送 Jar

那么如何在没有这些警告的情况下修复此问题来扫描我的代码呢?

仅供参考:

Jenkins 1.555

声纳 4.2

Sonar Runner 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 build中运行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] ------------------------------------------------------------------------

由于

1 个答案:

答案 0 :(得分:3)

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

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