So this article is more about integrating SONAR tool with your gradle builds.
What is SONAR? How can you get benefited form it, is something not in scope of this article. you can google a lot of good content is available. I just wanted to keep it short. so that you can quickly integrate your SONAR with gradle build.
Step 1: Hope you are done with installation of sonar, and you are able to create a sonar project. Once you are able to create sonar project, you have info about your project key and project name
Step2: In project level build.gradle add dependencies
dependencies {
classpath “org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1”
}
apply plugin: ‘org.sonarqube’
apply from: ‘sonar.gradle’
Step3: Create a file with name sonar.gradle and add below contents to it
apply plugin: ‘org.sonarqube’
sonarqube {
properties {
property “sonar.host.url”, “http://sonar.test.com:9000"
property “sonar.projectKey”, “com.test.project”
property “sonar.projectName”, “test project”
property “sonar.login”, “secret key of sonar which you use to login”
property “sonar.exclusions”,”files you want to exclude during scan”
property “sonar.sourceEncoding”, “UTF-8”
property “sonar.sources”, “src/main/java” // first defines where the java files are
property “sonar.scm.provider”, “git”
property “sonar.android.lint.report”, “build/outputs/lint-results-betaDebug.xml” // path to lint reports
}
}
Step4: Run command gradlew sonarqube
Step5: Login to sonar http://sonar.test.com:9000 view results