Reputation: 835
I have written a plugin that generates java classes based on some metadata in another file type. We currently have an in-house Ant task that does this and I am just calling that Ant task from Gradle to do the conversion.
However what I want to be able to do in my plugin is manipulate the projects sourceSets to add the destination directory. How do I access the sourceSets of a project from within the plugin?
e.g. Let's say the metadata was an xsd that I run through the xjc ant task (it is not but this is similar). I specify the output directory as an ext property on the project and I dont want to also have to add this same value to the sourceSet, I want the plugin to insert it for me so the compile step will automatically include the generated code.
Thanks
Upvotes: 4
Views: 2133
Reputation: 123968
The plugin gets passed the project in its apply
method. From there the procedure is very similar to a build script, e.g. project.apply plugin: "java"; project.sourceSets { ... }
. Note that the concept of source sets is added by the Java (base) plugin, so you have to apply that first.
Upvotes: 4