Can custom type only be allowed or introduced by custom plugin?

(Eric Deandrea) #1

I’ve written a bunch of custom plugins and also a couple of types (in this example I’ll use my custom XJC type - generating java sources from an XSD schema). It seems that once the jar file containing my custom plugins/jars is wired into the gradle distribution, that users can create tasks of my custom type regardless of which plugins are applied. In the case of java code generation, this really only makes sense if the java plugin (or better yet my own custom plugin which internally applies the java plugin and does some other stuff). XJC code generation really should require the java plugin to have been applied, since part of the custom type’s job is to modify the main sourceSet and add the xjc output directory to the sourceSet, and then make sure that the compileJava task depends on the instance of each task of the XJC type (so that the sources get generated BEFORE compileJava runs).

Anyone have any info on this?

(Peter Niederwieser) #2

A class is available iff it is on the build script class path. This is unrelated to whether or not a plugin has been applied. Task types shouldn’t reach out into the Gradle model (e.g. by configuring a source set). They should get everything they need as an input so that they stay flexible and aren’t tied to the model. (A good test is whether it’s possible to add multiple tasks of the same type with different configurations, e.g. one for each source set.) Manipulation of the model should be left to plugins.

(Eric Deandrea) #3

I got it - so my plugin should look for all tasks of a certain type and then do things with it - manipulate the source sets, set the dependencies of tasks, etc. That seems like a better way to do it.

Thanks for the pointer.