SonarRunner in gradle 2.2 doesn't take sonar.host.url parameter

SonarRunner in gradle 2.2 doesn’t seem to take sonar.host.url parameter - it always points to “http://localhost:9000” regardless of either Gradle code or -D flags.

I’ve tried to set the sonar host via the Gradle config, the properties file, and as a flag on the command line as per the Gradle documentation.

Regardless of how we try to set it, we always get the same error message:

SonarQube Runner 2.3 Java 1.7.0_71 Oracle Corporation (64-bit) Mac OS X 10.9.5 x86_64 INFO: Runner configuration file: NONE INFO: Project configuration file: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/sonar-project.properties INFO: Default locale: “en_US”, source code encoding: “UTF-8” (analysis is platform dependent) INFO: Work directory: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/.sonar ERROR: Sonar server ‘http://localhost:9000’ can not be reached

Our Sonar server is on version 3.7.1 of SonarCube.

This worked with Gradle 2.1.

It looks like none of the properties from the Gradle config are being utilized.

I’ve tried setting the sonarRunner to various older versions without success.

Here’s our config section: sonarRunner {

String SONAR_PROJ_NAME = System.getenv(‘GO_PIPELINE_NAME’) ?: “das.webapp”

sonarProperties {

property “sonar.host.url”,

http://sonar.xxxx.net:8020

property “sonar.jdbc.url”,

“jdbc:mysql://sonar.xxxx.net:3306/sonar”

property “sonar.jdbc.driverClassName”, “com.mysql.jdbc.Driver”

property “sonar.jdbc.username”,

“sonar”

property “sonar.jdbc.password”,

“sonar”

property “sonar.dynamicAnalysis”,

“reuseReports”

property “sonar.java.coveragePlugin”, “jacoco”

property “sonar.jacoco.reportPath”,

“${buildDir}/coverage-results/jacoco.exec”

property “sonar.projectKey”,

“${SONAR_PROJ_NAME}”

property “sonar.projectName”,

“${SONAR_PROJ_NAME}”

property “sonar.description”,

“Ecommerce web application”

} }

Any ideas? This is preventing us from upgrading to 2.2.

Hi Doug,

If you run the build with ‘-i’, the Sonar Runner task will log all of its properties before executing. What value do you see for the host in that property list?

Hi Doug,

see my comment on this thread: http://forums.gradle.org/gradle/topics/sonar_runner_gradle_task_is_not_compatible_with_sonar_4_4

You probably run into the same problem, that the sonar runner is forking, so you need to make sure you pass system properties and system environment down to the child process.

we do something like this:

sonarRunner {
        forkOptions {
            // copy environment to child process.
            environment = System.getenv()
      }
   }

Here’s the output wit

:test (Thread[Daemon worker,5,main]) completed. Took 15.573 secs. :sonarRunner (Thread[Daemon worker,5,main]) started. :sonarRunner Executing task ‘:sonarRunner’ (up-to-date check took 0.001 secs) due to:

Task has not declared any outputs. Executing Sonar Runner with properties: [sonar.projectName: das.webapp, sonar.projectDescription: DAS webapp, sonar.projectVersion: 1.5, sonar.projectBaseDir: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration, sonar.dynamicAnalysis: reuseReports, sonar.projectKey: das.webapp, sonar.environment.information.key: Gradle, sonar.environment.information.version: 2.2, sonar.working.directory: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/sonar, sonar.java.source: 1.7, sonar.java.target: 1.7, sonar.sources: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/main/resources,/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/main/groovy,/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/main/java, sonar.tests: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/test/resources,/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/test/groovy,/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/src/test/java, sonar.binaries: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/classes/main,/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/resources/main, sonar.libraries: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.j… many jars removed s/Home/jre/lib/rt.jar, sonar.surefire.reportsPath: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/test-results, sonar.junit.reportsPath: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/test-results, sonar.host.url: http://10.216.216.249:8020, sonar.jdbc.url: jdbc:mysql://10.216.216.249:3306/sonar, sonar.jdbc.driverClassName: com.mysql.jdbc.Driver, sonar.jdbc.username: sonar, sonar.jdbc.password: sonar, sonar.java.coveragePlugin: jacoco, sonar.jacoco.reportPath: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/coverage-results/jacoco.exec, sonar.description: Ecommerce web application, sonar.exclusions: /excel/,/WorkspaceSummaryDto,/WorkspaceSummaryProcess,/SaveOrCopyWorkspaceProcess,/AssortmentProcess,/AddProductProcess,/EditedOfferingFilterProductsProcess,/CartProcess,/AssortmentUtils,/AssortmentMigrateAV,/CpdProductToDasProductMapper,**/SyncDefaultAssortmentProcess] Starting process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java’’. Working directory: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration Command: /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java -Dproject.home=/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration -Dproject.settings=/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/tmp/sonarRunner/sonar-project.properties -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp /Users/Shared/Development/NikeBuild/gradleHome/caches/modules-2/files-2.1/org.codehaus.sonar.runner/sonar-runner-dist/2.3/48e39e521b2888a5ab775f9220666597850562/sonar-runner-dist-2.3.jar org.sonar.runner.Main Successfully started process ‘command ‘/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java’’ Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true SonarQube Runner 2.3 Java 1.7.0_71 Oracle Corporation (64-bit) Mac OS X 10.9.5 x86_64 INFO: Runner configuration file: NONE INFO: Project configuration file: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/sonar-project.properties INFO: Default locale: “en_US”, source code encoding: “UTF-8” (analysis is platform dependent) INFO: Work directory: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/.sonar ERROR: Sonar server ‘http://localhost:9000’ can not be reached INFO: ------------------------------------------------------------------------ INFO: EXECUTION FAILURE INFO: ------------------------------------------------------------------------ Total time: 0.038s Final Memory: 3M/245M ERROR: Error during Sonar runner execution INFO: ------------------------------------------------------------------------ ERROR: java.net.ConnectException: Connection refused ERROR: Caused by: Connection refused ERROR:

ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch. ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging. :sonarRunner FAILED :sonarRunner (Thread[Daemon worker,5,main]) completed. Took 0.198 secs.

FAILURE: Build failed with an exception.

You can see the host server is listed properly.

Tried that, didn’t work…

I can also see that in the build/tmp/sonarRunner/sonar-project.properties the settings are right, too (many lines deleted for clarity):

#Thu Nov 13 14:02:45 PST 2014 sonar.environment.information.version=2.2 sonar.jdbc.driverClassName=com.mysql.jdbc.Driver sonar.host.url=http://10.216.216.249:8020 sonar.java.source=1.7 sonar.java.coveragePlugin=jacoco sonar.projectDescription=DAS webapp sonar.projectVersion=1.5 sonar.java.target=1.7 sonar.surefire.reportsPath=/Users/Shared/Development/NikeBuild/nikeDev/das/branches/merge_avintegration/build/test-results sonar.environment.information.key=Gradle sonar.description=Ecommerce web application sonar.projectName=das.webapp sonar.jdbc.url=jdbc:mysql://10.216.216.249:3306/sonar sonar.projectBaseDir=/Users/Shared/Development/NikeBuild/nikeDev/das/branches/merge_avintegration

Noticing that the line

sonar.environment.information.version=2.2

shows 2.2, I set the version number to 2.2 as well, same result as the default of 2.3

Ok, so this tells me that we are passing what we think we are passing to Sonar but that it needs the host to be set in some other way. I’ve raised GRADLE-3195 for this.

Thanks, it looked like I was doing everything right :slight_smile:

Hey Douglas, I tried to reproduce the issue and I think it is not really a bug in gradle. It seems the sonar-runner automatically picks up properties from a sonar-project.properties file if it finds one in the working directory (which is the project directory when using gradles sonarRunner). From your logs you can see that gradle passes the project configuration file explicitly:

 -Dproject.settings=/Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/build/tmp/sonarRunner/sonar-project.properties

But it seems the properties file in the project directory wins over the generated file:

INFO: Project configuration file: /Users/Shared/Development/NikeBuild/nikeDev/das/branches/avintegration/sonar-project.properties

Is there a reason for having this sonar-project.properties in your project directory?

The property “sonar.environment.information.version” is usually used to pass further information about the environment where the sonar analysis took place. In gradle we just set the gradle version there. This could be misleading as the sonar runner currently operates in the same version range (2.2)

If you can confirm my findings, I would like to mark the issue as “not a bug”.

cheers, René

that was an old config file left over from the previous version of the sonar plugin - removing it fixed the problem.

Thanks!

Excellent,
thanks for letting us know.
cheers,
René