Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running sonar analysis with mvn sonar:sonar ignores sonar-project.properties

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?

like image 388
Paul Verest Avatar asked Jul 14 '17 05:07

Paul Verest


People also ask

What does Mvn sonar sonar will do?

What happens when you run mvn sonar:sonar is that an analysis report is generated and submitted to the server for asynchronous processing. Once the report is successfully submitted to the server, the local process ends.

How do I get sonar project properties?

SonarQube Properties and Parameters Global analysis parameters, defined in the UI, apply to all the projects (From the top bar, go to Settings > General Settings) Project analysis parameters, defined in the UI, override global parameters (At a project level, go to Configuration > Settings)

How do I set sonar scanner properties?

Inside your “sonarqube-scanner” folder, go to “conf” folder and find “sonar-scanner. properties” file. Open it in edit mode. Add these two basic properties in “sonar-scanner.

What is the mandatory parameter for project analysis in SonarQube?

Mandatory Parameters Allowed characters are: letters, numbers, - , _ , . and : , with at least one non-digit. Comma-separated paths to directories containing source files.


2 Answers

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
like image 69
janos Avatar answered Oct 08 '22 17:10

janos


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>
like image 31
Paul Verest Avatar answered Oct 08 '22 19:10

Paul Verest