Skip to content

Instantly share code, notes, and snippets.

@suclike
Last active October 19, 2015 09:11
Show Gist options
  • Save suclike/77afdde46a5c10a7dc14 to your computer and use it in GitHub Desktop.
Save suclike/77afdde46a5c10a7dc14 to your computer and use it in GitHub Desktop.
Gradle file for Android that contains code coverage and code checkers enabled
/**
* Android code analysis and reporting tools
*/
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
...
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:0.2.1'
}
}
apply plugin: 'jacoco'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'sonar-runner'
jacoco {
toolVersion = "0.7.5.201505241946"
}
findbugs {
toolVersion = "3.0.0"
}
repositories {
mavenLocal()
mavenCentral()
// for cwac dependencies
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'https://dl.bintray.com/accengage/maven' }
maven { url "http://repo1.maven.org/maven2/" }
maven { url "https://plugins.gradle.org/m2/" }
}
task jacocoTestReport(type: JacocoReport, dependsOn: "test${BUILD_FLAVOR}") {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml{
enabled = true
destination "$buildDir/XMLreports/jacocoReport/jacoco.xml"
}
csv.enabled false
html{
enabled = true
destination "$buildDir/HTMLreports/jacocoReport/jacocoHtml"
}
}
doFirst {
// no inspection GroovyAssignabilityCheck
executionData = files(executionData.findAll { it.exists() })
}
def coverageSourceDirs = [
"$projectDir/src/main/java",
]
classDirectories = fileTree(
dir: "$buildDir/intermediates/classes",
excludes: ['**/R*.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/*$InjectAdapter.*',
'**/*$ModuleAdapter.*',
'**/*$ViewInjector*.*',
'**/Manifest*.*',
'**/*Test*.*',
'**/R\$*.class',
'**/*\$*.class'
]
)
additionalSourceDirs = files(coverageSourceDirs)
sourceDirectories = files(coverageSourceDirs)
executionData = files("$buildDir/jacoco/test${BUILD_FLAVOR}.exec")
afterEvaluate {
// just clean up coveralls dashboard, following reports are not of interest
testMasterDebug.reports.junitXml.enabled = false
}
}
task findbugs(type: FindBugs, dependsOn: "assemble${BUILD_FLAVOR}") {
description 'Run findbugs'
group 'Verification'
classes = fileTree("$buildDir/intermediates/classes")
source = fileTree("$projectDir/src/main/java")
classpath = project.configurations.compile
ignoreFailures = true
effort = 'max'
reportLevel = "high"
// excludeFilter = file("findbugs-exclude.xml")
reports {
xml{
enabled = true
destination "$buildDir/XMLreports/findbugs/findbugs-report.xml"
}
html.enabled = false
}
}
task checkstyle(type: Checkstyle, dependsOn: "assemble${BUILD_FLAVOR}") {
description 'Run checkstyle'
group 'Verification'
configFile file("${projectDir}/assets/reportrules/checkstyle-hard.xml")
// configProperties.checkstyleSuppressionsPath =
// file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
showViolations = true
ignoreFailures = true
source "$projectDir/src"
include "**/*.java"
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
def configProps = ['proj.module.dir': projectDir.absolutePath]
configProperties configProps
// empty classpath
classpath = files()
reports {
xml{
enabled = true
destination "$buildDir/XMLreports/checkstyle/checkstyle-report.xml"
}
}
}
task pmd(type: Pmd, dependsOn: "assemble${BUILD_FLAVOR}") {
description 'Run findbugs'
group 'Verification'
ignoreFailures = true
ruleSetFiles = files("${projectDir}/assets/reportrules/pmd-ruleset.xml")
ruleSets = []
source "${projectDir}/src"
include '**/*.java'
exclude '**/gen/**'
reports {
xml{
enabled = true
destination "$buildDir/XMLreports/pmd/pmd-report.xml"
}
html.enabled = false
}
}
sonarRunner {
sonarProperties {
property "sonar.host.url", "$SONAR_ADDERESS"
property "sonar.login", "$SONAR_LOGIN"
property "sonar.password", "$SONAR_PASSWORD"
property "sonar.jdbc.url", "$SONAR_DB"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "$SONAR_DB_LOGIN"
property "sonar.jdbc.password", "$SONAR_DB_PASSWORD"
property "sonar.sources", "${projectDir}/src"
property "sonar.binaries", "$buildDir/classes/debug"
property "sonar.jacoco.reportPath", "$buildDir/jacoco/test${BUILD_FLAVOR}.exec"
property "sonar.profile", "Android Lint"
property "sonar.projectKey", "$SONAR_PROD_KEY"
property "sonar.projectName", "$SONAR_PROJECT_NAME"
property "sonar.projectVersion", "1.0-SNAPSHOT"
property "sonar.projectDescription", "$SONAR_PROJECT_DESCRIPTION"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment