Creating a Jar of test binaries - Gradle
GradleGradle Problem Overview
I'm using the latest version of Gradle (milestone 9), and I'm trying to figure out how to create a Jar of all test binaries.
From what I've found on the internet, the following should work:
task packageTests(type: Jar) {
from sourceSets.test.classes
}
However I am getting a -
> Cannot get the value of write-only property 'classes' on source set > test.
What is the correct way of coding what I'm trying to achieve?
Is the property 'classes' somehow deprecated now ?
Gradle Solutions
Solution 1 - Gradle
Changing sourceSets.test.classes
to sourceSets.test.output
fixes the problem.
Solution 2 - Gradle
In 2021 there is the Kotlin DSL now, so the latest answer looks like:
tasks.register<Jar>("packageTests") {
from(sourceSets.test.get().output)
}
Solution 3 - Gradle
I do it with Gradle / Groovy like this:
https://github.com/tomasbjerre/gradle-scripts/commit/d550e6bf79574b4920b7910e48ebd94ca959cece
task testJar(type: Jar, dependsOn: testClasses) {
classifier = 'test'
from sourceSets.test.allSource
}