yes its a bit tricky for a project with multiple modules,its achieved using proper wildcards.
follow these steps:
in the master module which contains all the sub-modules place the
sonarqube.gradle file
in the build.gradle file of the master module add the maven plugin and
class dependencies
here is an example of two above mentioned files:
sonarqube.gradle
apply plugin: "org.sonarqube"
sonarqube {
//noinspection GroovyAssignabilityCheck
properties {
//noinspection GroovyAssignabilityCheck
property "sonar.projectName", "appar"
//noinspection GroovyAssignabilityCheck
property "sonar.projectVersion", "1.0"
//noinspection GroovyAssignabilityCheck
property "sonar.analysis.mode", "publish"
//noinspection GroovyAssignabilityCheck
property "sonar.language", "java"
//noinspection GroovyAssignabilityCheck
property 'sonar.sourceEncoding', "UTF-8"
//noinspection GroovyAssignabilityCheck
property "sonar.sources", "./src/main"
// noinspection GroovyAssignabilityCheck
property "sonar.exclusions", "src/main/java/com/appar/model/**, **/*Entity.java"
//noinspection GroovyAssignabilityCheck
property "sonar.host.url", "http://192.168.21.33:9000"
//noinspection GroovyAssignabilityCheck
property "sonar.login", "admin"
//noinspection GroovyAssignabilityCheck
property "sonar.profile", "fulllint"
//noinspection GroovyAssignabilityCheck
property 'sonar.import_unknown_files', true
//noinspection GroovyAssignabilityCheck
property "sonar.android.lint.report", "./build/outputs/lint-results-debug.xml"
//noinspection GroovyAssignabilityCheck
property "sonar.password", "admin"
//noinspection GroovyAssignabilityCheck
property "sonar.java.binaries", "build/"
}
}
build.gradle
buildscript {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.0.1"
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
}
}
allprojects {
repositories {
jcenter()
}
}
then apply from sonarqube.gradle in build.gradle of separate modules
here is an example of build.gradle of one of the sub modules:
apply plugin: 'com.android.library'
apply from: '../sonarqube.gradle'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
}
dependencies {
compile project(':java-library')
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.1.4"
}
just put this line along with all other apply lines as shown in the above file
apply from: '../sonarqube.gradle'
after you apply sonarqube.gradle to all the build.gradle files in the sub modules.
just run the command
./gradlew sonarqube
trust me the project will successfully get build and get pushed into sonarqube server and the error results will get shown
if you are using findbugs make the project before pushing or else build will fail because the findbugs needs the bytecode to analyse.
And dont use the property
//noinspection GroovyAssignabilityCheck
property "sonar.projectKey", "appar_app"
This sonar.projectKey property. This is used by SonarQube to identify each project (or module) in sonar database.
So if all your modules have same projectKey value, SonarQube will update one single project in its database.
Don't worry, this property is automatically set with the folder name of each module.