I’ve been googling and reading a bunch of articles, but have not found a concise guide explaining in a modern and step by step style how to properly setup scanning of Gradle-based Java project.
What is required to be installed in the build machine
What is required to be installed in SonarQube
What is required to be setup in the gradle.properties
What is required to be setup in the Java project (for the unit tests results)
What is required to be added to the sonar-project.properties file
All of these above would be required in order to:
Scan unit tests
Verify project meets coverage threshold defined in the quality gate
This was very simple to achieve for Node.js-based projects, but I’m having difficulty doing the same for Java (I am not a Java developer, so not as familiar…).
In the Java project, I edited the build.gradle file by adding this block:
plugins {
id "org.sonarqube" version "2.6.2"
}
Now the guide mentions to run gradle sonarqube, but how do I integrate this in my Jenkinsfile?
Additionally it’s not totally clear to me how a complete sonar-project.properties file would look like.
For our Node.js projects we use SonarQube Scanner in this manner (in the Jenkinsfuile):
withSonarQubeEnv('****') {
sh "../../../sonar-scanner/bin/sonar-scanner"
}
qualitygate = waitForQualityGate()
if (qualitygate.status != "OK") {
currentBuild.result = "FAILURE"
slackSend (...)
}
It’s not clear to me what is the equivalent for Java projects.
These are two aspects(4 & 5) that are well documented for other project types but not at all for Java / Gradle.
Regarding sonar-project.properties, since you’re using Gradle to analyze, you don’t need it. The values necessary to analysis with either be picked up automatically by Gradle, or passed through your Gradle file.
However, the Coverage was not calculated. What am I missing in the setup to get coverage so it could be checked against the quality gate’s coverage threshold?