sonar.host.url not working with sonar-maven-plugin

2019-01-23 15:52发布

问题:

After upgrading my POMs to sonar-maven-plugin:2.7 the configuration does not work any more. My configuration in settings.xml is like this:

<profile>
  <id>sonar</id>
  <properties>
    <sonar.jdbc.url>jdbc:postgresql://my.server:5432/sonar</sonar.jdbc.url>
    <sonar.jdbc.driverClassName>org.postgresql.Driver</sonar.jdbc.driverClassName>
    <sonar.jdbc.username>xxxxx</sonar.jdbc.username>
    <sonar.jdbc.password>yyyyy</sonar.jdbc.password>
    <sonar.host.url>http://my.server</sonar.host.url>
  </properties>
</profile>

The build is started with -Psonar of course. With version 2.6 everything is fine, with 2.7 I get

[INFO] --- sonar-maven-plugin:2.7:sonar (default-cli) @ myproject ---
[INFO] User cache: C:\Users\me\.sonar\cache
[ERROR] SonarQube server 'http://localhost:9000' can not be reached
...
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.7:sonar (default-cli) on project myproject: Fail to download libraries from server: java.net.ConnectException: Connection refused: connect -> [Help 1]

Starting the build with -X gives me the correct mojo configuration in both cases, especially the url is still correct in the log

[DEBUG]   (f) sonarHostURL = http://my.server

Even deleting the mentioned caching directory does not help.

What can I do except of managing the plugin to version 2.6?

回答1:

Workaround: Adding -Dsonar.host.url=http://my.server:9000 to mvn command works for me



回答2:

We are investigating the issue. Ticket was created: https://jira.sonarsource.com/browse/MSONAR-129

In the meantime you could either lock the SQ plugin to version 2.6 or pass all properties using command line.



回答3:

Better than disabling the plugin, you may fix the plugin version to 2.6, which works fine, taking into account sonar.host.url.

For instance, with Maven in my case:

<pluginManagement>
  </plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>sonar-maven-plugin</artifactId>
      <version>2.6</version>
      <!-- sonar.host.url not working with version 2.7 -->
    </plugin>
  </plugins>
</pluginManagement>


回答4:

I use the full qualified goal in the CI server to run the sonar goals:

mvn org.codehaus.mojo:sonar-maven-plugin:2.6:sonar

Since we use the templates in TeamCity this is not so much of a disaster. Still we were a bit surprised by the event.



回答5:

Both

"mvn -Dsonar.host.url=http://localhost:9000 org.codehaus.mojo:sonar-maven-plugin:2.6:sonar"

and

"mvn -Dsonar.host.url=http://localhost:9000 org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar"

worked for me.



回答6:

Instead of reconfiguring all jobs I disabled sonar for all jobs until this gets fixed. I added

<sonar.skip>true</sonar.skip>

to the sonar profile in settings.xml.



标签: sonarqube