Gradle cannot resolve dependencies for Sonar-Runner

I am using Gradle 2.2.1 and I am trying to set up sonar analysis using the Sonar Runner plugin. My Sonar server is 4.3.1 and I am using Sonar-Runner version 2.4. I have the Sonar-Runner artifact in a hosted nexus repository, and I confirmed the artifacts are in fact there. When I try to run gradle build sonar, I get the following error:

Could not resolve all dependencies for configuration ‘:sonarRunner’. Cannot resolve external dependency org.codehaus.sonar.runner:sonar-runner-dist:2.4 because no repositories are defined.

In my build.gradle I have the Apply plugin: ‘sonar-runner’. What am I doing wrong?

Did you declare your Nexus repository in your build script that also applies the Sonar Runner plugin?

I have the nexus repo declaration and the sonarRunner{} block in our master build file

Can you post the relevant build code? What exactly do you mean if you refer to the “master” build file?

I meant the root build file. And no matter what I have in the Sonar Runner block, I get this error, but here is what I have:

apply plugin: ‘sonar-runner’ sonarRunner { toolVersion = “2.4”

sonarProperties {

property “”, “$sonarHost”

property “sonar.analysis.mode”, “incremental”

} }

I don’t see you repository definition. I assume you are just not showing it?

Do me a favor and add the following to your root build script and run the task ‘copyLibs’. You should be able to download the dependency if everything is set up correctly.

configurations {
  dependencies {
    sonar 'org.codehaus.sonar.runner:sonar-runner-dist:2.4'
  repositories {
    // define your repo
  task copyLibs(type: Copy) {
    from configurations.sonar
    into "$buildDir/libs"

It seems my issue is that I had the repositories definition only in the buildscript block. I added another repositories outside of the buildscript and it worked thank you!

If you define the repository inside of ‘buildscript’ it means that it can only be used for dependencies declared within the ‘buildscript’ block.

I just checked and this is not valid:

buildscript {
   repositories {
      maven {
url "$nexus"
 classpath 'org.codehaus.sonar.runner:sonar-runner-dist:2.4'

Does this have to do with us applying the sonar-runner plugin?

You don’t have to do that. Remove the whole ‘buildscript’ block. It is only needed if you want to manage libraries or plugins for your build script and not your application. For a deeper understanding please read the relevant chapter in the user guide. They only think you will have to do is to declare your Nexus (outside of ‘buildscript’). The Sonar Runner plugin takes care of resolving the correct coordinates for that dependency under the covers.