Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Jar of test binaries - Gradle

Tags:

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 ?

like image 361
vicsz Avatar asked Apr 05 '12 18:04

vicsz


People also ask

How do I create a test report in Gradle?

How to generate a Test Report. Gradle generates a Test Report automatically when it runs the entire Test Suite. To do the same, run ./gradlew test (or gradlew. bat test from Windows), or run the test Gradle task from your IDE.

Does Gradle build include test?

By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. This detection uses different criteria depending on the test framework used. For JUnit, Gradle scans for both JUnit 3 and 4 test classes.


Video Answer


2 Answers

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

like image 160
vicsz Avatar answered Oct 02 '22 18:10

vicsz


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

tasks.register<Jar>("packageTests") {     from(sourceSets.test.get().output) } 
like image 44
Mike Hearn Avatar answered Oct 02 '22 18:10

Mike Hearn