[multi-project]: setting cross-project testCompile dependency fails at runtime

I have a multi-project setup with an api project that includes a test source set that contains a test utility class.

I want to use this utility class in all the other test source sets in the other subprojects.

So, I have this entry for the other subprojects in the root build.gradle script:

project(':subproject-impl') {
    dependencies {
        compile project(':subproject-api')
        testCompile project(':subproject-api').sourceSets.test.output
    }
}

With this entry, and no other special configuration for the test task in the root or subprojects, I’m expecting the subproject to compile and successfully load the api test classes when its tests run.

Compilation of the test source set in the subproject succeeds, but when the tests run, I get a NoClassDefFoundError for the api test class.

Why is this happening? How can I fix it?

Never mind - the NoClassDefFoundError was coming from a different missing dependency.

Nothing to see here!