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

查看:29
本文介绍了如何配置 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>
</profiles>


Then run the following:

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