Sonar分析Maven 3和使用JENKINS的多语言项目 [英] Sonar analysing Maven 3 and multi language project using JENKINS

查看:2478
本文介绍了Sonar分析Maven 3和使用JENKINS的多语言项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在 Maven 3 Java JS 项目中使用 Sonar strong> JENKINS 。



要分析我的项目,我选择了两种不同的方式,但是两者都不能正常工作。 >

第一种方法:在JENKINS中启动Sonar作为独立任务作为后构建操作



Sonar插件 v2.1从 JENKINS 安装



Sonar Runner v2.3安装从 JENKINS



在我的maven项目的后构建部分,我选中启动 Sonar 设置以下属性:

 #必需的元数据
sonar.projectKey = ***
sonar.projectName = ***
sonar.projectVersion = 1.0
sonar.java.source = 1.7

#父源代码目录的路径。
sonar.sources = src / main

#Path到目录排除
sonar.exclusions = src / main / webapp / ui / ext / **,src / main / webapp / ui / build / **,src / main / webapp / ui / admin / sass / **,src / main / webapp / ui / user / sass / **,src / main / ressources / **

#Path到类目录
sonar.binaries = target / classes

#Path到Junit测试报告和测试文件
sonar.junit.reportsPath = target / surefire-reports
sonar.tests = src / test
sonar.dynamicAnalysis = reuseReports

#Jacoco coverage报告
sonar.jacoco.reportPath = target / jacoco。 exec
sonar.java.coveragePlugin = jacoco

#源代码的编码
sonar.sourceEncoding = UTF-8

通过这种方式,我可以分析 JAVA JS 不会加载 maven 依赖关系。这是 SONAR 分析时的日志:

  09:23:55.605 INFO  -  Java字节码扫描。 .. 
09:23:55.646 WARN - 类'org / springframework / context / ApplicationContext'不能通过ClassLoader访问。
09:23:55.656 WARN - Class'com / mongodb / MongoClient'不能通过ClassLoader访问。
09:23:55.657 WARN - Class'com / mongodb / DB'无法通过ClassLoader访问。
09:23:55.661 WARN - 类'org / springframework / context / ApplicationContext'不能通过ClassLoader访问。
09:23:55.662 WARN - 类'org / springframework / context / ApplicationContext'不能通过ClassLoader访问。
...
09:23:55.749 WARN - 类'org / apache / log4j / Logger'不能通过ClassLoader访问。
09:23:55.773 INFO - Java bytecode scan done:168 m

声纳代码覆盖率...和分析 SUCCESSFUL 但我无法在我的版本中保留这些警告。



所以我使用 maven 进行了 Sonar 分析。



第二种方式: p>

Maven 插件v3.0.4从 JENKINS 安装



Sonar 插件v2.1从 JENKINS 安装



在构建部分之后,我选择Sonar,

  -Dsonar.projectKey = *** 
-Dsonar.projectName = ***
-Dsonar .projectVersion = 1.0
-Dsonar.java.source = 1.7

-Dsonar.sources = src / main

-Dsonar.exclusions = src / main / webapp / ui / ext / **,src / main / webapp / ui / build / **,src / main / webapp / ui / admin / sass / **,src / main / webapp / ui / user / sass / ** ,src / main / ressources / **

-Dsonar.binaries = target / classes

-Dsonar.junit.reportsPath = target / surefire-reports
- Dsonar.tests = src / test
-Dsonar.dynamicAnalysis = reuseReports

-Dsonar.jacoco.reportPath = target / jacoco.exec
-Dsonar.java.coveragePlugin = jacoco

-Dsonar.sourceEncoding = UTF-8

没有更多的classe加载器问题和所有的依赖性加载。



Sonar 只分析 JAVA 代码,即使我定义 sonar.sources = src / main 他只分析 JAVA



这是日志:

  [INFO] --- sonar-maven-plugin:2.2:sonar(default-cli)@ WebDark --- 
[INFO] SonarQube版本:4.2
信息:默认语言环境:fr_FR,源代码编码:UTF-8
....
[INFO] [15:20:59.054] / ** / jenkins / jobs / ** / workspace
[INFO] [15:20:59.054]工作目录:/ ** / ** / jenkins / jobs / ** / workspace / sonar
[INFO] [15:20:59.054]源dirs:/ ** / ** / jenkins / jobs / ** / workspace / src / main / java
[INFO] [15:20 :59.054]测试dirs:/ ** / ** / jenkins / jobs / ** / workspace / src / test / java
[INFO] [15:20:59.054]二进制文件:/ ** / ** / jenkins / jobs / WebDark / workspace / target / classes
[INFO] [15:20:59.055]源编码:UTF-8,默认语言环境:fr_FR
[INFO] [15:20:59.055 ]索引文件
[INFO] [15:20:59.083]排除的来源:
...
...

同样,分析 SUCCESSFUL ,但 SONAR 不分析 JS 。正如你在日志中看到的, Source dirs 设置为 / ** / ** / jenkins / jobs / ** / workspace /即使我在 -Dsonar.sources = src / main 之前设置了


$ b $ src / main / java
b

因此,有可能在依赖关系 Maven 项目中分析 JAVA JS 使用 SONAR JENKINS ,而不是警告/错误,并以正确
SONAR 有限制吗?



感谢您协助我的讯息,并协助我解决我的问题。

解决方案

我希望通过指出本文档的第一段来帮助你:



It sais...因此,对于多语言项目,属性通常必须重写为:sonar.sources = src。注意,此属性只能在pom文件中设置,不是可以通过命令行设置。



http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven#AnalyzingwithMaven-AnalyzingaMulti-languageProject



祝你好运!


Here is a problem/issue found while using Sonar in a Maven 3 Java JS project using JENKINS build.

To analyse my project , I've choosen two different way, but both doesn't work as it should.

First way : Launching Sonar as standlone task as a post-build action in JENKINS

Sonar Plugin v2.1 Installed from JENKINS

Sonar Runner v2.3 Installed from JENKINS

In post-build section of my maven project, I check Launch Sonar as standlone task and I set these properties :

# Required metadata
sonar.projectKey=***
sonar.projectName=***
sonar.projectVersion=1.0
sonar.java.source=1.7

# Path to the parent source code directory.
sonar.sources=src/main

#Path to the directories to exclude
sonar.exclusions=src/main/webapp/ui/ext/**,src/main/webapp/ui/build/**,src/main/webapp/ui/admin/sass/**,src/main/webapp/ui/user/sass/**,src/main/ressources/**

#Path to classes directory
sonar.binaries=target/classes

#Path to Junit test reports and test files
sonar.junit.reportsPath=target/surefire-reports
sonar.tests=src/test
sonar.dynamicAnalysis=reuseReports

#Jacoco coverage report
sonar.jacoco.reportPath=target/jacoco.exec
sonar.java.coveragePlugin=jacoco

# Encoding of the source code
sonar.sourceEncoding=UTF-8

With this way I can analyse both JAVA and JS as I want.But, SONAR doesn't load maven dependencies as they should be loaded. Here is the log when SONAR analyse :

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 m

I can see in Sonar the code coverage...and the analyse is SUCCESSFUL But I can't keep these WARNINGS in my build.

So I did a Sonar analyse using maven.

Second way : Soanar using maven

Maven plugin v3.0.4 Installed from JENKINS

Sonar plugin v2.1 Installed from JENKINS

In after build section I choose Sonar and I set these properties :

 -Dsonar.projectKey=***
 -Dsonar.projectName=***
 -Dsonar.projectVersion=1.0
 -Dsonar.java.source=1.7

 -Dsonar.sources=src/main

-Dsonar.exclusions=src/main/webapp/ui/ext/**,src/main/webapp/ui/build/**,src/main/webapp/ui/admin/sass/**,src/main/webapp/ui/user/sass/**,src/main/ressources/**

-Dsonar.binaries=target/classes

-Dsonar.junit.reportsPath=target/surefire-reports
-Dsonar.tests=src/test
-Dsonar.dynamicAnalysis=reuseReports

-Dsonar.jacoco.reportPath=target/jacoco.exec
-Dsonar.java.coveragePlugin=jacoco

-Dsonar.sourceEncoding=UTF-8

Using this way, I have no more classe loader problem and all the dependencies are loaded.

But Sonar only analyse the JAVA code, even if I define sonar.sources=src/main he only analyse JAVA.

Here is the log :

[INFO] --- sonar-maven-plugin:2.2:sonar (default-cli) @ WebDark ---
[INFO] SonarQube version: 4.2
INFO: Default locale: "fr_FR", source code encoding: "UTF-8"
....
[INFO] [15:20:59.054] Base dir: /**/**/jenkins/jobs/**/workspace
[INFO] [15:20:59.054] Working dir: /**/**/jenkins/jobs/**/workspace/target/sonar
[INFO] [15:20:59.054] Source dirs: /**/**/jenkins/jobs/**/workspace/src/main/java
[INFO] [15:20:59.054] Test dirs: /**/**/jenkins/jobs/**/workspace/src/test/java
[INFO] [15:20:59.054] Binary dirs: /**/**/jenkins/jobs/WebDark/workspace/target/classes
[INFO] [15:20:59.055] Source encoding: UTF-8, default locale: fr_FR
[INFO] [15:20:59.055] Index files
[INFO] [15:20:59.083] Excluded sources:
...
...

Again, the analyse is SUCCESSFUL but, SONAR doesn't analyse JS. And as you can see in the log, the Source dirsis set to /**/**/jenkins/jobs/**/workspace/src/main/java even if I seted before -Dsonar.sources=src/main.

So , is it possible to analyse both JAVA and JS in a Maven project with many dependencies using SONAR and JENKINS with no WARNING/ERROR and in a proper way ? Does SONAR have limits ?

Thank you for concidering my post and help me resolving my issue.

解决方案

I hope I can help you by pointing out to you the first paragraph of this documentation:

It sais "...Therefore, for a multi-language project, the property usually has to be overridden to: sonar.sources=src. Note that this property can only be set in the pom file. It's not possible to set it via the command line."

http://docs.codehaus.org/display/SONAR/Analyzing+with+Maven#AnalyzingwithMaven-AnalyzingaMulti-languageProject

Good Luck!

这篇关于Sonar分析Maven 3和使用JENKINS的多语言项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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