修复“无法通过 ClassLoader 访问类."Jenkins、SonarQube 和 Gradle 的警告 [英] Fixing 'Class is not accessible through the ClassLoader.' warning with Jenkins, SonarQube, and Gradle

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

问题描述

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

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.

这些库都在我的 build.gradle 中列为依赖项.

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

我在这里阅读 关于使用 sonar.libraries 属性,我将在其中给出 Jar 的路径.但是因为 Gradle 为我下载了这些依赖项,所以路径在我的机器上看起来像这样:/home/siberut/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.5/6b262da268f8ad9eff941b25503a9198f0a0ac93/slf4j-api-1.7.5.jar.

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.

那么我怎样才能摆脱这些警告呢?有没有办法让 Gradle 告诉 SonarQube 罐子的位置?

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?

谢谢

我正在使用 SonarQube 服务器 4.1.1,Gradle 插件 1.23Sonar 插件 2.1、Sonar Runner 2.3 和 gradle --version 给出:

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

这是包含所有警告的构建的完整控制台输出:Link

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

Jenkins 像这样调用 my build.gradle:

Jenkins calls my build.gradle like this:

Jenkins 像这样调用 SonarQube:

Jenkins calls SonarQube like this:

就像 Peter Niederwieser 所说,让 Gradle 调用 SonarQube 可以消除警告.我的配置的相关部分是 这里.

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

推荐答案

你必须设置 sonar.libraries.但要手动设置此属性,您必须定义一个 Gradle 任务,将所有外部依赖项复制到 lib 目录,然后使用 sonar.libraries=path/to/lib/*.jar 引用它们.相反,我会通过 sonar-runner Gradle 插件调用 Sonar,它会为您设置上述属性(加上 sonar.libraries 和其他属性).

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天全站免登陆