Hello!
I am experiencing a problem with the Android gradle SonarQube plugin when I want to specify a sonar.host.url other than localhost:9000. I cannot get the setting to take effect.
My analysis of the source it seems that the host.url parameter may be overwritten by sonarqube plugin. See details below:
Precondition
- Here is the version of the plugin I am using in my gradle script
$ ./gradlew buildEnvironment
…
-– org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1
-– org.sonarsource.scanner.api:sonar-scanner-api:2.9.0.887
- There is NO local sonarqube host.
Steps to reproduce
A. I specify sonar.host.url via the command line:
$ ./gradlew -Dsonar.host.url=http://sonar-host -Dsonar.verbose=true --stacktrace sonarqube
Note that specifying -DsystemProp.sonar.host.url=… produce same end-result.
And adding setting to gradle.properties also results in below problem.
The build fails. Here is the interesting part of the stack trace:
Task …:sonarqube FAILED
SonarQube server [http://localhost:9000] can not be reached
…
Caused by: org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarQube
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:84)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory$1.run(IsolatedLauncherFactory.java:71)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:71)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:67)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:218)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:156)
at org.sonarqube.gradle.SonarQubeTask.run(SonarQubeTask.java:98)
Analysis
From:
sonar-scanner-gradle/src/main/java/org/sonarqube/gradle/SonarQubeTask.java
line 82: public void run() {
…
EmbeddedScanner scanner = EmbeddedScanner.create(LOG_OUTPUT)
.setApp("ScannerGradle", getPluginVersion() + "/" + getProject().getGradle().getGradleVersion())
97: .addGlobalProperties(propertiesObject);
scanner.start();
scanner.runAnalysis(propertiesObject);
scanner.stop();
}
From:
sonar-scanner-api/api/src/main/java/org/sonarsource/scanner/api/EmbeddedScanner.java
line 154: public void start() {
initGlobalDefaultValues();
doStart();
}
line 183: private void initGlobalDefaultValues() {
setGlobalDefaultValue(ScannerProperties.HOST_URL, “http://localhost:9000”);
setGlobalDefaultValue(InternalProperties.SCANNER_APP, “SonarQubeScanner”);
setGlobalDefaultValue(InternalProperties.SCANNER_APP_VERSION, ScannerApiVersion.version());
}
Analysis
line 184 of EmbeddedScanner.java start() seems to overwrite the HOST_URL parameter with a call to initGlobalDefaultValue() that was set in SonarQubeTask.java line 97 with addGlobalProperties()
Later versions (e.g. 2.7.1) of the plugin has a similar chain of calls and also seems overwrite the HOST_URL parameter too.
Best regards