我可以使用不同的排除项在声纳中对同一个Maven项目进行两次分析吗? [英] Can I analyze the same maven project twice in sonar, using different sets of exclusions?

查看:68
本文介绍了我可以使用不同的排除项在声纳中对同一个Maven项目进行两次分析吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由Sonar分析(在Jenkins中)的多模块Maven项目.这将创建一个Sonar项目,其中包含我的Maven项目的整个代码库的指标. Sonar项目的ID与我的Maven项目的ID相同.因此,如果我的Maven项目是 Foo (带有模块 M1 M2 M3 ),那么我会发现声纳项目 Foo 已创建,我可以看到组件 M1 M2 M3 的度量. /p>

我想知道我是否可以创建另一个对Maven项目的子集进行分析的Sonar项目.我可以使用Maven + Cobertura来做到这一点,方法是指定一个Maven配置文件,该配置文件定义要包含在Cobertura分析中(或从Cobertura分析中排除)的一组软件包.这使我可以生成一组Cobertura报告:一个用于整个项目,一个用于 X Y Z 包;等

所以我现在要看的是创建一个名为 Bar 的Sonar项目,该项目是为Maven项目 Foo 计算指标的结果,而该Sonar项目将是配置为仅包含软件包 X Y Z (可以包含在模块 M1 中, M2 等).它将作为詹金斯工作开始,签出Maven项目 Foo 并调用 sonar 生成后操作,以某种方式指定Sonar项目名称​​ Bar 而不是默认为 Foo .然后(我希望)我将有两个Sonar项目: Foo 代表整个Maven项目,而 Bar 代表那个Maven项目的子集.

我想知道(a)这是否可能,并且(b)可行吗?我不确定Sonar数据库是否会损坏(Sonar项目 M1 , M2 M3 > Foo 和 Bar ,它们可能会相互覆盖数据库条目.)

更新1

在Jenkins中调用声纳时,也许可以使用sonar.branch属性作为构建后的动作.

例如

詹金斯第一任职

  • SCM:检出Maven项目 Foo
  • 构建步骤:clean install -DskipTests
  • 构建后操作:声纳

詹金斯第二职业

  • SCM:检出Maven项目 Foo
  • 构建步骤:clean install -DskipTests
  • 构建后操作:声纳-Dsonar.branch=Bar

如有必要,我可以为Sonar中的 Bar 分支设置包含/排除.这种方法的缺点是,声纳分析在两个不同的分支上进行了两次.一次运行声纳分析然后查询数据库以根据需要缩小焦点范围会更加有效.

更新2

我遇到了一个问题:尽管我可以在分支上运行声纳分析,但是原始(非分支)Maven项目的声纳分析失败了.声纳分析花费了3倍的时间,才能因MySQL错误而失败:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.

The last packet successfully received from the server was 28,962,745 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.

但是,在其他Maven项目上进行声纳分析时,我没有看到任何MySQL错误.

解决方案

您的编辑正确.使用sonar.branch属性会创建一个不同的ID,即从Sonar的角度来看,这是一个不同的项目.

您可以将sonar.branch属性包含在栏"配置文件中(当然,您需要在第二份工作中调用该配置文件),从而确保您的数据库不会损坏.

是的,您需要对项目进行两次分析,但是这样做更加简洁(以后您可以选择对条形图使用不同的规则).

但是,您不一定需要创建两个作业,您可以将Sonar分析用作构建动作,而不是后期构建动作.

使用商业Views插件,您可能无需两次构建就可以实现效果.

I have a multi-module Maven project that is analyzed (within Jenkins) by Sonar. This creates a Sonar project containing metrics for the entire code base of my Maven project. The Sonar project has the same ID as the ID of my Maven project. So if my Maven project is Foo (with modules M1, M2, and M3) then I observe that a Sonar project Foo is created, and I can see the metrics for components M1, M2, and M3.

I am wondering if I can create another Sonar project that performs analysis on a subset of the Maven project. I can do this with Maven + Cobertura, by specifying a Maven profile that defines the set of packages to be included in (or excluded from) the Cobertura analysis. This allows me to produce a set of Cobertura reports: one for the project as a whole, one for a packages X, Y and Z; etc.

So what I am looking at now is creating a Sonar project called Bar that is the result of calculating metrics for the Maven project Foo, and that Sonar project will be configured in such a way to include only packages X, Y, Z (which may live in modules M1, M2, etc). It will kick off as a Jenkins job, checking out Maven project Foo and calling the sonar post-build action, somehow specifying Sonar project name Bar instead of defaulting to Foo. Then (I hope) I will have two Sonar projects: Foo representing the entire Maven project, and Bar representing a subset of that Maven project.

I'm wondering if (a) this is possible, and (b) will it work? I'm not sure if the Sonar database will be corrupted (there will be modules M1, M2, and M3 in the Sonar projects Foo and Bar, these may overwrite the database entries for each other).

Update 1

Maybe I can use the sonar.branch property when invoking sonar as a post-build action in Jenkins.

e.g.

Jenkins Job One

  • SCM: checks out maven project Foo
  • Build Step: clean install -DskipTests
  • Post-Build Action: sonar

Jenkins Job Two

  • SCM: checks out maven project Foo
  • Build Step: clean install -DskipTests
  • Post-Build Action: sonar -Dsonar.branch=Bar

I can setup the inclusions/exclusions for the Bar branch in Sonar, as necessary. The downside of this approach is that the sonar analysis is run twice on two different branches. It would be much more efficient to run the sonar analysis once and then query the database to narrow the focus as required.

Update 2

I'm running into a problem: although I can run a sonar analysis on the branch, the sonar analysis of the original (non-branch) Maven project is failing. The sonar analysis is taking 3 times as long, before it fails with MySQL errors:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure.

The last packet successfully received from the server was 28,962,745 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.

I don't get any MySQL errors when running a sonar analysis on other Maven projects, however.

解决方案

Your edit is correct. Using the sonar.branch property creates a different Id, i.e. from the Sonar point of view a different project.

You could include the sonar.branch property in your "bar"-profile (of course you need to call the profile in your second job) and thus make sure that your database does not get corrupted.

True, you would need to analyze the project twice, but is much more cleaner that way (and you could later choose to use different rules for your bar profile).

However you would not necessarily need to create two jobs, you can use a Sonar analysis as a build action instead of a post build action.

You might be able to achieve your effect without building twice using the commerical Views plugin.

这篇关于我可以使用不同的排除项在声纳中对同一个Maven项目进行两次分析吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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