How do I configure my Gradle build to fail when there are Sonar violations?
I want my Gradle build to fail if there are any are any critical or blocker violations in Sonar, is this functionality supported? If so, is it documented anywhere?
Execute gradle sonarqube -Dsonar.login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output. You should now be able to browse the analysis results.
You need to pass an authentication token using the sonar.login property in your command line or you configure it as part of your gradle.properties file. Execute gradle sonarqube -Dsonar.login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output.
Other installation failures If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.
If not, here are some things you might see instead. If you get "command not found: gradle", you need to ensure that Gradle is properly added to your PATH. If you get something like: ERROR: JAVA_HOME is set to an invalid directory Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
1) You must install the Build Breaker Plugin on the server side into /path/to/sonarqube/extensions/plugins/ see full instruction here
https://github.com/SonarQubeCommunity/sonar-build-breaker
2) you must use the SonarQube Scanner for Gradle
3) In your gradle config sonar.buildbreaker.skip properties must be false
buildscript {
repositories {
...
maven {
// for sonarqube
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
}
}
apply plugin: "org.sonarqube"
sonarqube {
properties {
property "sonar.projectKey", "your.project"
property "sonar.buildbreaker.skip" , "false"
}
}
4) You will probably want to add a Quality Gate in sonarQube (server side). For more information check this
It's not something that can be configured on the build side. Instead, the "build breaker plugin" has to be configured on the Sonar side. I'm not completely sure if it works with Gradle, but I think it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With