24

Latest 3.3 sonar-maven-plugin and 5.6 LTS as web server.
Running sonar analysis with mvn sonar:sonar ( Scanner for Maven )
ignores sonar-project.properties file. (with many parameters https://docs.sonarqube.org/display/SONAR/Analysis+Parameters)

Is it that the expected behavior?
So do I have to configure all sonar parameters within pom.xml files?

benzonico
  • 10,635
  • 5
  • 42
  • 50
Paul Verest
  • 60,022
  • 51
  • 208
  • 332

3 Answers3

31

That is correct: the scanner for Maven ignores the sonar-project.properties file.

To pass analysis parameters when using the scanner for Maven, set them as <properties> in the pom.xml, for example:

<properties>
    <sonar.host.url>http://yourserver</sonar.host.url>
</properties>

Or, you could also pass parameters using -D on the command line, for example:

mvn sonar:sonar -Dsonar.host.url=http://yourserver
janos
  • 120,954
  • 29
  • 226
  • 236
18

Other way would be to configure reading via Maven Properties Plugin

Q&A

   <build>    
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0.0</version>
        <executions>
          <execution>
            <phase>initialize</phase>
            <goals>
              <goal>read-project-properties</goal>
            </goals>
            <configuration>
              <files>
                <file>sonar-project.properties</file>
              </files>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
Görkem Mülayim
  • 1,139
  • 1
  • 12
  • 22
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • 3
    Any way to get this to fire with `mvn sonar:sonar`? For me this works only if you run something like `mvn verify sonar:sonar` – Tiris Sep 10 '19 at 13:27
  • Try `mvn properties:read-project-properties sonar:sonar` See https://www.mojohaus.org/properties-maven-plugin/ – Paul Verest May 08 '21 at 11:24
  • I don't know if this every got working and see this as acceptable answer, but the official documentation says that it is not possible and I quote In general, any of these parameters can be configured just like any other maven property (in order of override priority): On the mvn command line where the scanner goal is invoked, using the -D argument prefix. In the pom.xml file of the project. Unlike the plain-vanilla SonaScanner CLI, the SonarScanner for Maven uses the pom.xml instead of the sonar-project.properties file. In the global settings.xml. – Amaresh Kulkarni Oct 18 '22 at 20:49
0

From this documentation Sonar Scanner For Maven, it doesn't appear that Maven Sonar Scanner uses the sonar-project.properties. sonar-scanner CLI on the other hand does. So, I went with installing the sonar-scanner CLI