Gradle + grails + groovy + jacoco = Task 'jacocoTestReport' not found in root project 'appname'

I’m trying to use

apply plugin: 'jacoco'

on version 1.12.

When I run

./gradlew jacocoTestReport

it fails as a missing task.

./gradlew tasks

doesn’t show anything, either.

I’ve cargo-culted configuration from various example files but I can’t determine why it isn’t running. For instance, I’ve tried adding this config to my build.gradle:

jacoco {
  toolVersion = "0.6.3.201306030806"
  reportsDir = file("target/jacoco")
  destinationFile = file("target/jacoco.exec")
  enabled = true
}

(that didn’t make a difference)

I also added the following to the build.gradle file:

test {
  jacoco {
    destinationFile = file("target/jacoco.exec")
    enabled = true
  }
}

(again, no difference)

Finally I thought a missing sourceSets config was causing it, so I added this:

sourceSets {
  main.java.srcDirs = ["grails-app", "src"]
  test.java.srcDirs = ["test"]
}

(no difference).

So, what’s the minimal configuration necessary to get the jacoco task running with Grails?

Are you using the gradle-grails-plugin?

Luke- yes, using the gradle-grails-plugin, version 2.0.1.

@tedder42 -

Unfortunately you cannot use the built in Jacoco plugin with the Grails plugin because it is reliant upon having a Java/Groovy project. Grails projects are not Java/Groovy projects in the Gradle world. This is because Grails has it’s own build system and Gradle is merely calling out to it. Think of it, as Gradle is forking a process and waiting for it to return.

If you want to perform code coverage for you Grails projects, you should install the (Grails Test Code Coverage Plugin)[http://grails.org/plugin/code-coverage] and then configure gradle to execute the ‘grails-test-app’ task with the additional ‘-coverage’ argument.

It MAY be possible to configure Jacoco for covering the Grails tests, but it would be fairly involved. You would need to get the Jacoco library into a configuration in Gradle (you can copy what the Gradle plugin does for this), and then configured the javagent string for the ‘grails-test-app’ task.

thanks. I’m seeing major liability in using the Grails plugin, at least until grails3 arrives.