Skip to content

Instantly share code, notes, and snippets.

@jaredsburrows
Created February 10, 2018 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredsburrows/555fb1ccdf656c14aedb11341f08ece9 to your computer and use it in GitHub Desktop.
Save jaredsburrows/555fb1ccdf656c14aedb11341f08ece9 to your computer and use it in GitHub Desktop.
apply {
plugin("com.android.application")
plugin("jacoco")
plugin("com.github.kt3k.coveralls")
plugin("io.gitlab.arturbosch.detekt")
}
// Creates tasks based on the application build variant (productFlavor + buildType = variant)
android.applicationVariants.all { variant ->
def variantName = variant.name.capitalize()
def autoGenerated = ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/*ViewBinding*.*',
'**/BR.class',
'**/databinding/**',
'**/Companion/**',
'**/*Initializer*.*',
'**/*Test*.*',
'**/*$Lambda$*.*',
'**/*Module.*',
'**/*Dagger*.*',
'**/*MembersInjector*.*',
'**/*_Provide*Factory*.*']
/**
* Generates Jacoco coverage reports based off the unit tests.
*/
task("jacoco${variantName}Report", type: JacocoReport, dependsOn: "test${variantName}UnitTest") {
group "Reporting"
description "Generate ${variantName} Jacoco coverage reports."
reports {
xml.enabled = true
html.enabled = true
}
// variant.javaCompile.source does not work
// traverses from starting point
sourceDirectories = files(android.sourceSets.main.java.srcDirs + android.sourceSets.main.kotlin.srcDirs)
classDirectories = fileTree(dir: "$buildDir/intermediates/classes/debug", excludes: autoGenerated)
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/test${variantName}UnitTest.exec", // unit test - test${variantName}UnitTest
"outputs/code-coverage/connected/*coverage.ec" // android test - create${variantName}CoverageReport
])
}
}
detekt {
version = "1.0.0.RC4-3"
profile("main") {
input = "$projectDir/src/main/kotlin"
config = rootProject.file("${project.rootDir}/config/detekt/detekt.yml")
filters = ".*Test.*,.*/resources/.*,.*/tmp/.*"
}
}
coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml"
}
afterEvaluate {
tasks.findByName("check").dependsOn("detektCheck")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment