SonarQube is an open platform to manage code quality. As such, it covers the 7 axes of code quality:
1. Architecture and Design
2. Duplications
3. Unit Tests
4. Complexity
5. Potential bugs
6. Coding rules
7. Comments

Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven of declaring the project configuration. Gradle uses a directed acyclic graph (“DAG”) to determine the order in which tasks can be run.
Gradle was designed for multi-project builds which can grow to be quite large, and supports incremental builds by intelligently determining which parts of the build tree are up-to-date, so that any task dependent upon those parts will not need to be re-executed.

To integrate SonarQube and Gradle in an Android project you need set the build.grade file of the feature in this way:

buildscript {
    repositories {
        ....
    }
    dependencies {
        ....
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2'
    }
}
subprojects {
    ....
    apply plugin: "sonar-runner"
    sonarRunner {
        sonarProperties {
            properties["sonar.sources"] += "src/main/java"
        }
    }
}

task clean(type: Delete) {
    ....
}

allprojects {
    repositories {
        ....
    }
}

and build.gradle file of the app in this way:

apply plugin: "sonar-runner"
....

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
dataBinding {
        	enabled = true
    	    }
sonarRunner {
        sonarProperties {
            property "sonar.host.url", "http://localhost:9000"
            property "sonar.projectKey", "org.sonarqube:java-gradle-simple"
            property "sonar.projectName", "App Demo SonarQube"
            property "sonar.projectDescription", "App Demo SonarQube Description"
            property "sonar.projectVersion", "1.0"
            property "sonar.projectBaseDir", "app/src/main/java"
            property "sonar.working.directory", "build/sonar"
            property "sonar.scm.provider", "git"
        }
    }
....

Happy Static Testing with SonarQube!;)

share me!:))Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someonePrint this page