This message was deleted.
# plugin-development
s
This message was deleted.
c
We have a plugin that is applied, wrapped in a
Copy code
rootProject.pluginManager.apply(OurPlugin::class)
to only apply it to the root project
And a guard in the project
Copy code
require(target == target.rootProject)
From what I can tell its similar to this issue, https://stackoverflow.com/questions/29807622/gradle-artifactory-plugin-saying-cannot-cast-object-org-jfrog-gradle-plugin-ar but I’m not sure how it happens. We’re not using buildscript, but we’re still getting our plugin loaded in different classloaders?
c
Apply is idempotent, Gradle won’t apply the same plug-in class more than once. What does the extension registration code look like?
Possibly some classloader fun. How do the sub projects get the plug-in class?
c
That’s what I’m seeing. Unfortunately it is apply the plugin more than once
c
It will due to classloader - each sub project has a different class instance, tricking the root project into loading the plug-in multiple times. What is the intent here - perhaps there’s a different way to accomplish it.
c
if one of the plugins in the chain is applied false in the root build gradle, then it seems fine.
c
using the plugin-id will sidestep this as well.
c
not sure the plugin-id would prevent the extension from being loaded in two separate classloaders tho, right?
c
it would force the root project to load the class itself, not use the class provided by the subproject, at which point it would realize the plugin has already been applied. In theory. May be worth reviewing what the overall goal is here, perhaps a more robust approach is possible.
v
It would probably be better to just omit the wrapper plugin that applies the real plugin to the root project. Just let people apply the plugin to the root project. Latest when project isolation comes your approach will probably fail, but such cross-project configurations are questionable now already too.
c
Thanks for the input! Basic idea is we have ‘application’ or ‘library’ plugins that each have their own set of defaults for our company. We’d like to aggregate results from these plugins by reporting at the end of the build. For that we’d like to apply a plugin to the root that would make a ‘global’ extension available to all sub-projects.
From what I’m hearing, it might make more sense to require our ‘notify’ plugin to be applied in root, and then in subprojects check to see if the extension is registered and fail gracefully (or warn) if not.
c
sounds good. if you are doing this to aggregate information a shared BuildService may also be appropriate, instead of depending on cross-project dependencies.
c
Ah! That might be a good route.
Perhaps even output files that represent the build output, then collect that output similar to how normal gradle tasks handle input/output
c
likely no need to round-trip info through files - call a BuildService method with the info to aggregate and then summarize/output at the right spot.
c
Would a buildservice still have a problem with being registered in a subproject? Our would we expect the ‘root’ project to be applied?
v
You can register it anywhere
I'd also say that's the way to go