vicsz
vicsz

Reputation: 9764

Creating a Jar of test binaries - Gradle

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 ?

Upvotes: 58

Views: 22109

Answers (4)

Christos
Christos

Reputation: 934

with gradle 8 looks like this:

tasks.register('testJar', Jar) {
    dependsOn classes
    archiveClassifier = 'test'
    from sourceSets.test.allSource
}

tasks.named('assemble').configure {
    dependsOn 'testJar'
}

Upvotes: 0

Tomas Bjerre
Tomas Bjerre

Reputation: 3520

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
  }

Upvotes: 0

Mike Hearn
Mike Hearn

Reputation: 1473

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

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

Upvotes: 8

vicsz
vicsz

Reputation: 9764

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

Upvotes: 84

Related Questions