如何配置Maven以使用两个不同的质量配置文件运行SonarQube项目分析? [英] How to configure Maven to run a SonarQube project analysis with two different quality profiles?

查看:125
本文介绍了如何配置Maven以使用两个不同的质量配置文件运行SonarQube项目分析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们通过Maven为我们的Java项目运行SonarQube分析. Maven会自动地做到这一点.我们要做的就是将sonar-maven-plugin添加到我们的 pom.xml 中:

We run SonarQube analyses for our Java projects via Maven. Maven somehow does this automagically; all we did was add the sonar-maven-plugin to our pom.xml:

<pluginManagement>
    <plugins>
        ...
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.2</version>
        </plugin>
    </plugins>
</pluginManagement>

这很好.

但是现在我们需要使用不同的质量配置文件运行SonarQube分析两次.由于您无法轻松地从Maven更改项目密钥,因此我们使用SonarQube的branch属性来区分SonarQube项目,如下所示(同样是 pom.xml ):

But now we need to run the SonarQube analysis twice, with different quality profiles. Since you can't easily change the project key from Maven, we use SonarQube's branch property to differentiate the SonarQube projects, like this (again from pom.xml):

<properties>
    <sonar.profile>MyQualityProfile1</sonar.profile>
    <sonar.branch>Dev_${sonar.profile}</sonar.branch>
    ...
</properties>

这样,我们最终在SonarQube UI中有两个项目条目,两个项目都包含完全相同的代码,但是根据它们的质量配置文件(一个使用的质量配置文件1,另一个使用的质量配置文件2)存在不同的问题. ).

This way, we end up with two project entries in the SonarQube UI, both of which contain the exact same code, but have different issues depending on their quality profile (one used quality profile 1, and the other used quality profile 2).

问题:为了实现这一点,我必须手动更改 pom.xml 属性并运行两次整个构建.

Problem: In order to achieve this, I must manually change the pom.xml properties and run the entire build twice.

问题:如何配置maven以使用不同的属性简单地运行sonar:sonar目标两次?

Question: How can I configure maven to simply run the sonar:sonar goal twice with different properties?

这将为我们节省大量构建时间.我已经找到这个类似的问题,但到目前为止还没有答案.谢谢!

This would save us a lot of time on our builds. I already found this similar question, but no answers so far. Thanks!

推荐答案

扩展Eldad AK关于配置文件的先前答案:

Expanding on the previous answer given by Eldad AK regarding profiles:

创建两个Maven配置文件,如下所示:

Create two maven profiles as follows:

<properties>
  <sonar.branch>Dev_${sonar.profile}</sonar.branch>
</properties>

<profiles>
  <profile>
    <id>QualityProfileOne</id>
    <properties>
      <sonar.profile>MyQualityProfile1</sonar.profile>
    </properties>
  </profile>
  <profile>
    <id>QualityProfileTwo</id>
    <properties>
      <sonar.profile>MyQualityProfile2</sonar.profile>
    </properties>
  </profile>
</profile>

然后运行以下命令:

$ mvn clean install -DskipTests
$ mvn sonar:sonar -PQualityProfileOne
$ mvn sonar:sonar -PQualityProfileTwo

(不确定,您可能需要在运行声纳之间进行清洁)

(you may need to perform a clean between running sonar, not sure)

这篇关于如何配置Maven以使用两个不同的质量配置文件运行SonarQube项目分析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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