Add a folder as additional classes directory


In my project part of class files are generated by AspectJ from “aj” files.
How can I add this generated classes directory to the regular runtime configuration, so it will be added to jar and used during unit tests execution?
initially I thought to just output classes to the standard sourceSets.main.output.classesDir, but it will not play nice with Gradle 4.0 build caching.

(Chris Doré) #2

Do you want the generated classes to be included in the main jar, a secondary jar, or something else?


The main jar.
I found meanwhile a possible solution here, but did not have time to check it yet.

(Stefan Wolf) #4

How about adding it to sourceSets.main.output.classesDirs (note the trailing s)?

(Chris Doré) #5

Where is classesDirs defined? Doesn’t appear in

I was going to suggest

sourceSets.main.output.dir( <the path containing classes>, builtBy: 'theTaskThatGensTheClasses')

As show in the example in the SourceSetOutput docs.

(Stefan Wolf) #6

Using dir will work well. classesDirs is only available in Gradle 4.0:

For Gradle 4.0 we have separate classes directories for the different language source sets. Adding the AspectJ output directory as an output directory via dir as @Chris_Dore suggested makes perfect sense and is compatible with Gradle 3.x and Gradle 4.0.

(Chris Doré) #7

Thanks for the clarification Stefan.


I went with @Chris_Dore suggestion since we are still using Gradle 3.x and it solved the problem.

Thanks a lot.