Creating a Jar of test binaries - Gradle

Gradle

Gradle 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
  }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvicszView Question on Stackoverflow
Solution 1 - GradlevicszView Answer on Stackoverflow
Solution 2 - GradleMike HearnView Answer on Stackoverflow
Solution 3 - GradleTomas BjerreView Answer on Stackoverflow