修复'类不能通过ClassLoader访问'。警告Jenkins,SonarQube和Gradle [英] Fixing 'Class is not accessible through the ClassLoader.' warning with Jenkins, SonarQube, and Gradle

查看:498
本文介绍了修复'类不能通过ClassLoader访问'。警告Jenkins,SonarQube和Gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当SonarQube分析我的使用Gradle和Jenkins构建的Java项目时,我收到很多有关通过ClassLoader无法访问的第三方库的警告:

  WARN  -  Class'org / slf4j / Logger'不能通过ClassLoader访问。 
WARN - 类'com / google / gson / Gson'无法通过ClassLoader访问。

这些库在我的 a>。

解决方案

您必须设置 sonar.libraries 。但是为了手动设置这个属性,你必须定义一个Gradle任务,将所有的外部依赖拷贝到lib目录,然后使用 sonar.libraries = path / to / lib / *。jar 来引用它们。相反,我会通过 sonar-runner Gradle插件调用Sonar,该插件将负责设置上述属性(加上 sonar.libraries code>等)。


When SonarQube analyzes my Java project which is built using Gradle and Jenkins, I get a lot of warnings about third party libraries not being accessible through the ClassLoader:

WARN  - Class 'org/slf4j/Logger' is not accessible through the ClassLoader.
WARN  - Class 'com/google/gson/Gson' is not accessible through the ClassLoader.

These libraries are all listed as dependencies in my build.gradle.

I read here about using the sonar.libraries property where I'd give a path to the Jar. But because Gradle downloads those dependencies for me, the paths look like this on my machine: /home/siberut/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.5/6b262da268f8ad9eff941b25503a9198f0a0ac93/slf4j-api-1.7.5.jar.

And those paths change with every new version of the library.

So how can I get I get rid of those warnings? Is there maybe a way to let Gradle tell SonarQube about the location of the Jars?

Thanks

Edit: I'm using SonarQube Server 4.1.1, Gradle Plugin 1.23, Sonar Plugin 2.1, Sonar Runner 2.3 and gradle --version gives:

------------------------------------------------------------
Gradle 1.10
------------------------------------------------------------

Build time:   2013-12-17 09:28:15 UTC
Build number: none
Revision:     36ced393628875ff15575fa03d16c1349ffe8bb6

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy:          2.2.0
JVM:          1.7.0_21 (Oracle Corporation 23.7-b01)
OS:           Linux 3.10-2-486 i386

Here is the complete console output of a build including all the warnings: Link

Jenkins calls my build.gradle like this:

Jenkins calls SonarQube like this:


Edit: Just like Peter Niederwieser said, letting Gradle invoke SonarQube gets rid of the warnings. The relevant part of my configuration is here.

解决方案

You'll have to set sonar.libraries. But in order to set this property manually, you'll have to define a Gradle task that copies all external dependencies to a lib directory, and then use sonar.libraries=path/to/lib/*.jar to reference them. Instead, I'd invoke Sonar via the sonar-runner Gradle plugin, which will take care of setting the above properties (plus sonar.libraries and others) for you.

这篇关于修复'类不能通过ClassLoader访问'。警告Jenkins,SonarQube和Gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆