Creating a Jar of test binaries - Gradle

Changing sourceSets.test.classes to sourceSets.test.output fixes the problem.


In 2021 there is the Kotlin DSL now, so the latest answer looks like:

tasks.register<Jar>("packageTests") {
    from(sourceSets.test.get().output)
}