Apply Gradle Plugin to subprojects and root project via plugins block
Asked Answered
D

1

8

I have a multiproject gradle configuration and I wanted to add a plugin to all subprojects and the root project as well. Reading the docs here seems to be easy:

If you have a multi-project build, you probably want to apply plugins to some or all of the subprojects in your build, but not to the root or master project. The default behavior of the plugins {} block is to immediately resolve and apply the plugins. But, you can use the apply false syntax to tell Gradle not to apply the plugin to the current project and then use apply plugin: «plugin id» in the subprojects block or use the plugins {} block in sub projects build scripts

So basically the docs say: Apply false to only include the subprojects, don't apply anything and the plugin will be applied to all projects.

But this isn't working for me, I have to define the plugin at the root project build.gradle and then reapply it again in all subprojects, is this a bug?

Deberadeberry answered 30/5, 2019 at 19:50 Comment(7)
If you need to apply a plugin to all projects, you can use allprojects { apply plugin: 'myplugin' } in the root projectAureolin
Thanks, that works...but I did understand that from the docs, what does it say then, in a nutshell? What did I get wrongly?Deberadeberry
well it seems like with apply false , the plugin is "imported", but not applied to the root project. It can then be explicitly applied to subprojects (using apply plugin..)Aureolin
Yes, and with apply true, or no apply at all? We can infer from the docs that the plugin will be "imported", applied to the root project and all subprojects.... afterall, true should make the opposite of what false does.Deberadeberry
Well (as the docs say), the default behaviour is to apply the plugin- so you can omit apply true and the plugin is applied (and if you think of it, this is what happens whenever you apply plugin: 'java' to any project- the plugin is applied)Aureolin
Well, yes, and isn't this what I said? Or maybe I was too concise and left room for ambiguity?Deberadeberry
Besides, by your own comment, then according to the docs, there won't be needed an allprojects blockDeberadeberry
A
0

It doesn't work for me either. It seems to be a known limitation, although I could not find recent information about this. Have a look at this (2 years old) answer: https://mcmap.net/q/271615/-how-to-apply-plugin-to-allprojects-with-new-gradle-plugins-mechanism

Adulteration answered 8/11, 2019 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.