Unable to create a fat test jar with gradle

The problem is the following. The result of a Groovy closure (neglecting an explicit return statement) is the last line of the closure.

from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    configurations.testCompile.collect { it.isDirectory() ? it : zipTree(it) }
    sourceSets.test.output
}

So the code above will result in including only the compile test classes. You’ll want to do this.

from { configurations.testRuntime.collect { it.isDirectory() ? it : zipTree(it) }
from sourceSets.test.output

Couple of other things you might notice:

  1. No need to include both compile and testCompile since testCompile extends compile. That is, all compile dependencies are also automatically on the test compilation classpath.
  2. Really, you should be using testRuntime as you’ll need any and all runtime dependencies to actually execute the tests.