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.
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.
How about adding it to sourceSets.main.output.classesDirs
(note the trailing s
)?
Where is classesDirs
defined? Doesn’t appear in SourceSetOutput - Gradle DSL Version 8.4
I was going to suggest
sourceSets.main.output.dir( <the path containing classes>, builtBy: 'theTaskThatGensTheClasses')
As show in the example in the SourceSetOutput
docs.
Using dir
will work well. classesDirs
is only available in Gradle 4.0: https://docs.gradle.org/4.0-rc-3/dsl/org.gradle.api.tasks.SourceSetOutput.html#org.gradle.api.tasks.SourceSetOutput:classesDirs
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.
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.