Sonar runner gradle task is not compatible with sonar 4.4

sonar runner task is not compatible using the latest sonarqube server (4.4) Affects Gradle 1.11, 1.12 and 2.0 Sonar runner task failed with the following exception:

Fail to download libraries from server

This is http://issues.gradle.org/browse/GRADLE-3062. You can track the progress there.

Hi Peter,

I know you’re all very busy and I don’t want to annoy, but I still want to bring this topic back into discussion. At the moment there is no progress, no assignee, and no planned fix version on GRADLE-3062 - could please someone take care of this? There are more and more users upgrading sonar, and they all cannot use the gradle plugin anymore…

Regards,

Oliver

There is a pull request in the works: https://github.com/gradle/gradle/pull/257

Hi Peter,

thanks for the update. I’m testing the nightly build 2.2-20140904223451 at the moment. A few things I would like to give feeback on.

  • Now that sonar-runner is forking, you now need to take care of copying environment variables over to the child process. We use it for things like sonar urls etc. – something that might be worth mentioning in the release notes.

  • unlike gradle, the sonar-runner is very unforgiving regarding missing directories. We have a multiproject that contains integrationTest as additional source set, but not all subprojects contain this directory. If you take the code from the example (properties[“sonar.tests”] += sourceSets.integTest.allSource.srcDirs) you will get null errors in those cases. The best solution I could come up with was this:

allprojects {

def iT = project.file(“src/integration/java”).exists()

def t = project.file(“src/test/java”).exists()

sonarRunner {

sonarProperties {

properties[“sonar.tests”] = (t?“src/test/java”:"") + (t&&iT?",":"") + (iT?“src/integration/java”:"")

property “sonar.jacoco.itReportPath”, “build/jacoco/integrTest.exec”

}

} }

which looks a bit ugly. Don’t know if there are better ways of doing this. I still cannot analyze my project, as I’m getting an error from sonar. Is there a way to activate debug logging or a stack trace from sonar to get to the root cause of the error?

ERROR: Error during Sonar runner execution ERROR: Unable to execute Sonar ERROR: Caused by: Fail to decorate ‘org.sonar.api.resources.Project@46d8824b[id=19365,key=…,qualifier=BRC]’ ERROR: Caused by: This is not a JSON Array. 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.

Here’s the workaround i used:

subprojects {
 // adding 'integTest' sourceset to Sonar properties only if it source files exist to prevent exceptions
 sourceSets.all {
  if (name == 'integTest') {
   boolean integTestSSFound = false
   java.srcDirs.each {
    if (it.exists() && it.isDirectory() && it.list().size() > 0) {
     integTestSSFound = true
    }
   }
   if(integTestSSFound) {
    sonarRunner {
     sonarProperties {
      properties["sonar.tests"] += sourceSets.integTest.allSource.srcDirs
     }
    }
   }
  }
 }
}

> Now that sonar-runner is forking, you now need to take care of copying environment variables over to the child process.

Can you elaborate on this? Are there special env vars that the runner looks for?

> Is there a way to activate debug logging or a stack trace from sonar to get to the root cause of the error? 

Not currently. The ‘SonarRunner’ task should at best have ‘setDebug()’ type methods for different command line switches, and at worst allow you to directly set args. These options aren’t mutually exclusive I guess.