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

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

问题描述

我有一个由 Sonar 分析(在 Jenkins 内)的多模块 Maven 项目.这将创建一个 Sonar 项目,其中包含我的 Maven 项目的整个代码库的指标.Sonar 项目的 ID 与我的 Maven 项目的 ID 相同.因此,如果我的 Maven 项目是 Foo(带有模块 M1M2M3),那么我观察到声纳项目 Foo 已创建,我可以看到组件 M1M2M3 的指标.

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.

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

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.

所以我现在正在查看的是创建一个名为 Bar 的 Sonar 项目,它是为 Maven 项目 Foo 计算指标的结果,该 Sonar 项目将是配置为仅包含包 XYZ(可能存在于模块 M1 中,M2 等).它将作为 Jenkins 工作启动,检查 Maven 项目 Foo 并调用 sonar 构建后操作,以某种方式指定 Sonar 项目名称 Bar而不是默认为 Foo.然后(我希望)我会有两个 Sonar 项目:Foo 代表整个 Maven 项目,Bar 代表该 Maven 项目的一个子集.

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.

我想知道 (a) 这是否可行,以及 (b) 是否可行?我不确定 Sonar 数据库是否会损坏(Sonar 项目中会有模块 M1M2M3>Foo 和 Bar,它们可能会互相覆盖数据库条目).

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).

更新 1

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

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

例如

詹金斯工作一

  • SCM:检查 maven 项目 Foo
  • 构建步骤:全新安装 -DskipTests
  • 构建后操作:声纳

Jenkins 工作二

Jenkins Job Two

  • SCM:检查 maven 项目 Foo
  • 构建步骤:全新安装 -DskipTests
  • 构建后操作:声纳 -Dsonar.branch=Bar

我可以根据需要为 Sonar 中的 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.

更新 2

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

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:

原因:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链路故障.

从服务器成功接收到的最后一个数据包是 28,962,745 毫秒前.最后一个成功发送到服务器的数据包是在 0 毫秒前.

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

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

推荐答案

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

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

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

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