在 jenkins 插件中正确设置 sonar.sources [英] correctly setting sonar.sources in jenkins plugin

查看:30
本文介绍了在 jenkins 插件中正确设置 sonar.sources的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个 Android java 项目 分支:feature-Fprototype_app

I am trying to build an Android java project branch: feature-Fprototype_app

我收到此错误:

[INFO] [13:38:36.470] Base dir: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile 
[INFO] [13:38:36.470] Working dir: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/target/sonar 
[INFO] [13:38:36.470] Source dirs: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src 
[INFO] [13:38:36.470] Binary dirs: /Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/target/classes 
[INFO] [13:38:36.470] Source encoding: UTF-8, default locale: en_US 
[INFO] [13:38:36.489] Sensor JavaSourceImporter... 
[INFO] [13:38:36.710] Sensor JavaSourceImporter done: 221 ms 
[INFO] [13:38:36.710] Sensor JavaSquidSensor... 
[INFO] [13:38:36.800] Java AST scan... 
[ERROR] Sonar is unable to analyze file : '/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java/com/simpragma/apps/textify/db/BookmarkDao.java' 
[INFO]
    ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------- 
[INFO] Total time:14.245s 
[INFO] Finished at: Thu Oct 17 13:38:36 GMT+05:30 2013 
[INFO] Final Memory: 14M/102M 
[INFO]
    ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project Textify: Can not execute SonarQube analysis: Sonar is unable to analyze file :

    **'/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java/com/simpragma/apps/textify/db/BookmarkDao.java': The source directory does not correspond to the package declaration** com.simpragma.apps.textify.db -> 
[Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project Textify: Can not execute SonarQube analysis

在 jenkins 配置 Post Build Action 我试图在 Additional properties 框中设置 sonar.sources (因为当我搜索错误,人们建议为源设置正确的路径).我尝试了很多组合,例如:

In jenkins configuration Post Build Action I am trying to set the sonar.sources in Additional properties box (because when i googled for the error, people suggested to set the correct path for sources). I tried many combinations like:

 -Dsonar.sources=mobile/src/main/java
 -Dsonar.sources=/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile/src/main/java
 -Dsonar.sources=/Users/Shared/Jenkins/Home/jobs/Textify/workspace/mobile

还是一样的错误.我做错了什么?

still same error. What am I doing wrong ?

好吧,让我清理一下我造成的混乱. 首先,它是一个 android maven 项目.包结构是 com.xyz.abc,源根目录是 src/main/java.在 pom.xml 中,sourceDirectory 属性最初设置为指向 src.看来maven对源码的根没有任何问题,它正在编译项目.然后,我为这个项目设置了 jenkins 和 sonar.我使用 Jenkins 的 Post-build Action 对我的项目设置声纳分析.这里的问题是使用 Maven 运行分析时,总是忽略某些 SonarQube 属性,因为 SonarQube 在内部从 POM 提供它们" - SONAR-4536.其中一个属性是 sonar.sources .因此,当我在 Jenkins 设置中尝试使用 -Dsonar.sources 时,它不起作用.后来我修改了我的 pom 以指向 src/main/java 这导致通过 jenkins 构建后操作成功分析.

ok let me clear the mess I have created. Firstly, it is an android maven project. The package structure is com.xyz.abc and source root was src/main/java. In pom.xml the sourceDirectory property was initially set to point to src. It seems maven does not have any issue with the root of source, it is compiling the project. Then, I set up jenkins and sonar for this project. I used Jenkins's Post-build Action to set up Sonar analysis on my project. The catch here is "When running an analysis with Maven, some SonarQube properties are always ignored because SonarQube internally feeds them from the POM" - SONAR-4536. One among such properties is sonar.sources . Therefore, when i tried with -Dsonar.sources in the Jenkins setup it did not worked. Later I modified my pom to point to src/main/java which resulted in successful analysis through jenkins post-build action.

我希望我已经澄清了.

推荐答案

如果您的项目是 Maven 项目并且您正在使用 SonarQube Maven 插件,则源位置取自 Maven 模型.属性 sonar.sources 仅在使用 SonarQube Runner 执行分析时使用.

If your project is a Maven project and you are using SonarQube Maven plugin then source location is taken from Maven model. The property sonar.sources is only used when using SonarQube Runner to perform the analysis.

查看您的项目 pom.xml 并检查 .另外请更新您的问题,以说明您是在使用常规 Java 项目还是其他任何项目(如 android).

Look at your project pom.xml and check . Also please update your question to tell if you are on a regular Java project or anything else (like android).

这篇关于在 jenkins 插件中正确设置 sonar.sources的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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