Can Sonar Scan be triggered as part of regular maven Build command like " mvn build"?

1k Views Asked by At

Im looking to see any maven configuration which will enable me to run Sonar Scan on my code for every maven build. I dont want to use a separate goal but somehow enforce it as part of users regular build commands.

1

There are 1 best solutions below

5
Sebastian Heikamp On

You can attach Sonar to a phase (e.g. verify) like this:

<plugin>
   <groupId>org.sonarsource.scanner.maven</groupId>
   <artifactId>sonar-maven-plugin</artifactId>
   <version>3.5.0.1254</version>
   <executions>
       <execution>
          <id>verify-sonar</id>
          <phase>verify</phase>
          <goals>
             <goal>sonar</goal>
          </goals>
        </execution>
    </executions>
</plugin>

This also works with other phases like compile or package.