How to configure Maven to run a SonarQube project analysis with two different quality profiles?

后端 未结 4 1318
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 03:19

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

相关标签:
4条回答
  • 2020-12-08 03:48

    Try to configure two executions of your plugin. Something like this:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <executions>
            <execution>
                <id>s1</id>
                <phase>verify</phase>
                <goals>
                    <goal>sonar</goal>
                </goals>
                <configuration>
                    <sonar.branch>MyQualityProfile1</sonar.branch>
                </configuration>
            </execution>
            <execution>
                <id>s2</id>
                <phase>install</phase>
                <goals>
                    <goal>sonar</goal>
                </goals>
                <configuration>
                    <sonar.branch>MyQualityProfile2</sonar.branch>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    This will start two executions of sonar in phases verify and install, each with another sonar.branch value. In Sonar you can then configure the required quality profiles after the first analysis.

    0 讨论(0)
  • 2020-12-08 03:58

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

    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>
    

    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)

    0 讨论(0)
  • 2020-12-08 04:00

    A combination of maven and Ant might work: Use Maven for the first sonar analysis as you already do and use the Maven Antrun Plugin to execute another SonarQube configuration defined using the SonarQube Ant Task.

    0 讨论(0)
  • 2020-12-08 04:03

    I would opt for the maven profiles.
    Each profile would have its own properties.

    I hope this helps.

    0 讨论(0)
提交回复
热议问题