Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle : sourceSets.test.classes not found

Tags:

gradle

I am trying to get my one of my projects (ProjectA) to generate a jar file containing all the test classes so that it can be used in ProjectB.

I did a bit of research and found this as possible solution: Create test jar artifact in gradle. That says that the following code snippet should do the trick.

apply plugin: 'java'

task testJar(type: Jar) {
   classifier = 'tests'
   from sourceSets.test.classes
}

However, when I add the above to my build.gradle, I get the following error message:

  • What went wrong:

A problem occurred evaluating root project 'gradle_project'.

Could not find property 'sourceSets' on task ':testJar'.

I have searched on both Google and the Gradle documentation for more information but either it has been removed without documenting it anywhere that I could find or I am using it wrong. I am suspecting the latter, just don't know what I am doing wrong.

I have tried the same code snippet inside mysubprojects{} section but then I got the following error message:

  • What went wrong:

A problem occurred evaluating root project 'gradle_project'.

Cannot get the value of write-only property 'classes' on source set test.

like image 870
zwessels Avatar asked May 31 '12 13:05

zwessels


1 Answers

Solved it with the steps below:

Step 1: Move the code snippet inside the subprojects{} section

Step 2: sourceSets.test.classes has been removed. sourceSets.test.output seems to do the trick. Found this: Creating a Jar of test binaries - Gradle

like image 90
zwessels Avatar answered Sep 25 '22 16:09

zwessels