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?
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 {
sonar
}
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!
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.