Created
February 12, 2012 17:16
-
-
Save stevendick/1809759 to your computer and use it in GitHub Desktop.
Gradle Multi-Project & JaCoCo
This file contains hidden or 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
subprojects { | |
apply plugin: 'java' | |
configurations { | |
codeCoverage | |
} | |
dependencies { | |
codeCoverage files("${rootProject.projectDir.path}/lib/jacocoagent.jar") | |
} | |
test { | |
// JaCoCo uses an agent to do code coverage instrumentation on loading rather than instrumenting class files on disk | |
// we set the jacoco property in case code needs to know that jacoco is active (otherwise some reflection tests fail) | |
jvmArgs "-javaagent:${configurations.codeCoverage.singleFile}=destfile=${buildDirName}/coverage-results/jacoco.exec,sessionid=HSServ,append=false", | |
'-Djacoco=true', | |
'-Xms128m', | |
'-Xmx512m', | |
'-XX:MaxPermSize=128m' | |
} | |
task copyCoverageData(dependsOn: test, type: Copy) { | |
from "${buildDirName}/coverage-results" | |
into "${rootProject.buildDir.path}/coverage-results" | |
include 'jacoco.exec' | |
rename 'jacoco.exec', "${project.name}.jacoco.exec" | |
} | |
} |
This file contains hidden or 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
generateCoverageReport.dependsOn { | |
subprojects.collect { project -> | |
project.copyCoverageData.path | |
} | |
} |
This file contains hidden or 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
task generateCoverageReport << { | |
ant { | |
taskdef(name:'jacocoreport', classname: 'org.jacoco.ant.ReportTask') { | |
classpath path: "${rootProject.projectDir.path}/lib/jacocoant.jar" | |
} | |
mkdir dir: "${buildDirName}/reports/coverage" | |
jacocoreport { | |
executiondata { | |
fileset(dir: "${buildDirName}/coverage-results") { | |
include name: '*.jacoco.exec' | |
} | |
} | |
structure(name: project.name) { | |
classfiles { | |
dependsOnProjects.each { project -> | |
fileset dir: "${project.buildDir.path}/classes/main" | |
} | |
} | |
sourcefiles(encoding: 'CP1252') { | |
dependsOnProjects.each { project -> | |
fileset dir: "${project.projectDir.path}/src/main/java" | |
} | |
} | |
} | |
xml destfile: "${buildDirName}/reports/coverage/jacoco.xml" | |
html destdir: "${buildDirName}/reports/coverage" | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment