Skip to content

Instantly share code, notes, and snippets.

@ben-manes
Created February 27, 2013 05:15
Show Gist options
  • Save ben-manes/5045293 to your computer and use it in GitHub Desktop.
Save ben-manes/5045293 to your computer and use it in GitHub Desktop.
apply from: "${rootDir}/coverage.gradle"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.ajoberstar:gradle-jacoco:0.1.0"
}
}
task wrapper(type: Wrapper, description: "Generates the gradle wrapper") {
gradleVersion = "1.4"
}
apply plugin: "java"
apply plugin: "jacoco"
import org.ajoberstar.gradle.jacoco.tasks.*
task coverageReport(type: JacocoReport) {
// can include one or more execution files
executionData = files(test.jacoco.destFile)
// must specify the classes that you want coverage data for
classFiles = sourceSets.main.output
// provide the source files that go along with those classes
sourceFiles = sourceSets.main.allSource
}
$ gradle build
FAILURE: Build failed with an exception.
* Where:
Script '/Users/bmanes/projects/jacoco/coverage.gradle' line: 6
* What went wrong:
A problem occurred evaluating script.
> Could not find property 'JacocoReport' on root project 'jocaco'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 1.473 secs
@ajoberstar
Copy link

If you change your coverage.gradle to the following it should work. It's not ideal, but there's some goofiness with how Gradle handles the classpath of applied scripts. An applied script can't reference classes from the build.gradle's classpath, but apply plugin: 'somestring' does seem to end up using it. Without declaring the buildscript dependency in both files, you need to reference the class name of the plugin.

buildscript { repositories { mavenCentral() } dependencies { classpath "org.ajoberstar:gradle-jacoco:0.1.0" } }

import org.ajoberstar.gradle.jacoco.tasks.*
import org.ajoberstar.gradle.jacoco.plugins.*

apply plugin: "java"
apply plugin: JacocoPlugin

task coverageReport(type: JacocoReport.class) {
// can include one or more execution files
executionData = files(test.jacoco.destFile)

// must specify the classes that you want coverage data for
classFiles = sourceSets.main.output

// provide the source files that go along with those classes
sourceFiles = sourceSets.main.allSource
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment