JaCoCo no subproject coverage

I’ve been using JaCoCo via the Gradle plugin and it’s been working well, but I’ve just moved some of my code base into subprojects and I’m no longer getting coverage.

The JaCoCo agent generates the exec file correctly.
The report is also generated and sessions page has the classes from the sub project, but there is no coverage in the main coverage page.

I’ve written an SSCCE for the problem:

├── build.gradle
├── settings.gradle
├── src
│   └── cucumber
│       ├── java
│       │   └── a
│       │       └── Steps.java
│       └── resources
│           └── test.feature
└── sub
    └── src
        └── main
            └── java
                └── a
                    └── Sub.java


plugins {
    id 'java'
    id 'jacoco'
    id 'com.github.samueltbrown.cucumber' version '0.9'

repositories {

cucumber {
    glueDirs = ['src/cucumber/java']
    featureDirs = ['src/cucumber/resources']

    jvmOptions {
        def jacocoAgent = zipTree(configurations.jacocoAgent.singleFile).filter { it.name == 'jacocoagent.jar' }.singleFile
        def jacocoResult = "$buildDir/results/jacoco/cucumber.exec"
        jvmArgs = ["-javaagent:$jacocoAgent=destfile=$jacocoResult,append=false"]

jacocoTestReport {
    executionData = files("$buildDir/results/jacoco/cucumber.exec")

    reports {
        html.destination "$buildDir/reports/jacoco"

dependencies {
    cucumberCompile 'info.cukes:cucumber-java:1.2.5'
    cucumberCompile project('sub')

subprojects {
    apply plugin: 'java'

I’ve tried playing with the properties of the jacocoTestReport task, but nothing seems to help.

I’m running on Arch linux with OpenJDK 8 and Gradle 3.3.

I find JaCoCo indispensable for creating quality software and would greatly appreciate any help.

By default, jacoco will only report coverage on sources in the same project as the tests. You’ll need to add the other project’s sources to the report

jacocoTestReport {
   additionalSourceDirs new File(rootProject.projectDir, 'sub/src/main/java') 

See JacocoReport.additionalSourceDirs

Thanks, that works!

When I try and make it a bit less hard coded it stopped working:

jacocoTestReport {
    sourceDirectories = project.files(subprojects.sourceSets.main.allSource.srcDirs)
    classDirectories = project.files(subprojects.sourceSets.main.output)

It works again if i shift the jacocoTestReport closure below the subprojects closure.