Best practices for plugin declaration and task visibility

Hi,

I have a couple of questions regarding Gradle conventions and best practice recommendations.

Given the following multi-project structure where projects project-java-* contain Java sources and project-NO-java-* do not:

root-project:
  -project-java-1
  ...
  -project-java-X
  -project-NO-java-1
  ...
  -project-NO-java-Y
  1. Is it all right to apply the java plugin at the root-project level or should I shortlist the project-java-* projects and apply the plugin only to them? I assume the same behaviour requirements would apply to custom plugins?

  2. Suppose I applied a custom plugin only to a sub-project. Should the plugin publish its tasks so that they could be visible and executed at the root project level?

Thanks,
Gin

Regarding 1., applying the java plugin to all projects instead of a subset will have a small performance impact… it’s likely that simplicity is better here. However, custom plugins may make more assumptions or have a higher overhead to each subproject if applied broadly. I suggest to start simple and measure performance and correctness, only making a change if one of those 2 aren’t met.

Regarding 2., one can invoke subproject tasks from the root as if they were at the root. See the 2nd point in that subsection. For example, even if the Java Plugin is applied to only 1 subproject, gradle compileJava from the root will work. Therefore, I don’t think any special action to “publish” tasks is needed.

HTH,
Eric