Created
May 26, 2015 23:50
-
-
Save nickwph/f9d390a99c3ce59404a2 to your computer and use it in GitHub Desktop.
Gradle build file to set up variables for JaCoCo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Nicholas Wong <[email protected]>. | |
* Gradle build file to set up variables for JaCoCo. | |
* The following tasks will be created in normal circumstance. | |
* | |
* - Create JaCoCo HTML and XML Reports | |
* jacocoDebug | |
* jacocoRelease | |
* | |
* - Open JaCoCo HTML Report in Mac OSX | |
* openJacocoHtmlDebug | |
* openJacocoHtmlRelease | |
*/ | |
apply plugin: 'jacoco' | |
jacoco.toolVersion = "0.7.4.201502262128" | |
afterEvaluate { | |
android.libraryVariants.each { variant -> | |
def variantName = variant.getName() | |
def variantNameCapitalized = variantName.capitalize() | |
def flavorName = variant.productFlavors[0].getName() | |
def buildTypeName = variant.buildType.getName() | |
def task = tasks.create(name: "jacoco${variantNameCapitalized}", type: JacocoReport, dependsOn: ["assemble${variantNameCapitalized}", "test${variantNameCapitalized}"]) { | |
group = "Report" | |
classDirectories = fileTree( | |
dir: "${buildDir}/intermediates/classes/${flavorName}/${buildTypeName}", | |
excludes: ['**/R.class', '**/R$*.class', '**/BuildConfig.*'] | |
) | |
additionalSourceDirs = files(android.sourceSets.main.java.srcDirs) | |
sourceDirectories = files(android.sourceSets.main.java.srcDirs) | |
executionData = files(["${buildDir}/jacoco/test${variantNameCapitalized}.exec", "jacoco.exec"]) | |
reports { | |
xml.enabled = true | |
xml.destination = "${buildDir}/reports/jacoco/${variantName}/index.xml" | |
html.enabled = true | |
html.destination = "${buildDir}/reports/jacoco/${variantName}" | |
} | |
} | |
tasks.create(name: "openJacocoHtml${variantNameCapitalized}", type: Exec, dependsOn: "jacoco${variantNameCapitalized}") { | |
group = "Report" | |
executable 'open' | |
args "${task.reports.html.destination}/index.html" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment