This is an Android multi-module demo app to verify the proper configuration of a Jenkins CI server and a SonarQube Server, should work straightforward if your sonarQube server is at localhost:9000
I have wrote two extensive Medium articles explaining:
In your app module add the Jacoco-android-gradle-plugin https://github.com/arturdm/jacoco-android-gradle-plugin
buildscript {
repositories {
...
jcenter()
}
dependencies {
...
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
}
}
apply plugin: 'jacoco-android'
jacoco {
toolVersion = jacocoVersion
}
In your java modules just add:
apply plugin: "jacoco"
jacoco {
toolVersion = jacocoVersion
}
In your parent build.gradle add:
ext {
jacocoVersion = '0.7.8'
}
In your parent build.gradle add these lines
plugins {
id "org.sonarqube" version "2.2.1"
}
sonarqube {
properties {
def jenkinsJobName = System.getenv('JOB_NAME')
def jenkinsJobBuild = System.getenv('BUILD_NUMBER')
def projectVersion = "nonJenkinsBuild_1.0"
def projectName = "HelloJenkins"
def projectKey = "hellojenkins:hellojenkins"
def branch = "master"
if (jenkinsJobName && jenkinsJobBuild) {
jenkinsJobName = jenkinsJobName.replace(" ", "_")
projectVersion = jenkinsJobName + '_' + jenkinsJobBuild
}
//change url if sonarqube is not at localhost:9000
property "sonar.host.url", "http://localhost:9000"
property "sonar.projectKey", projectKey // some shortcut name
property "sonar.projectName", projectName
property "sonar.projectVersion", projectVersion
property "sonar.branch", branch
property "sonar.sourceEncoding", "UTF-8"
property "sonar.scm.provider", "git"
property "sonar.java.coveragePlugin", "jacoco"
}
}
Note: if the Analysis is triggered from Jenkins server, environmental variables Job_Name and Buid_Number will be used to tag the reports, otherwise "nonJenkinsBuild_1.0" will be used.
In your app module add:
sonarqube {
properties {
property "sonar.jacoco.reportPath", "build/jacoco/testDebugUnitTest.exec"
property "sonar.junit.reportsPath", "build/test-results/debug"
}
}
Nothing is required in java modules.
If you want to test Firebase Test Lab integration checkout "feature/fireTestLab" branch.
If you want to test Genymotion Cloud integration please checkout "feature/genymotion" branch.
Amazon Device Farm doesn't require any project configuration