Clayton Walker
03/31/2025, 9:19 PMClayton Walker
03/31/2025, 9:20 PMClayton Walker
03/31/2025, 9:24 PMTrevJonez
03/31/2025, 9:25 PMVampire
03/31/2025, 11:17 PMbuildSrc
is another way as that lands on a parent classloader of the root project's one.
Adding the plugin with "apply false" to the settings script would be another way, as it is a parent classloader of the buildSrc
classloader iirc.
What effect depending on the plugin in an included build has, depends on where / how / and if you use that included build somewhere like applying a plugin from it.
Another reason for such actions could be version conflicts.
Because only stuff on the same classpath undergoes conflict resolution.
But stuff in parent classloaders wins over stuff in child classloaders by definition.
So if you for example
⢠apply plugin A in the root project
⢠apply plugin B in the subproject
⢠A needs C v1
⢠B needs C v2 and cannot work with v1
Then B will fail as it sees C v1 from the parent class loader.
Here again either depending on C v2 in the root buildscript or right away plugin B would fix it (as long as A can work with C v2) as then conflict resolution happens betwenn C v1 and C v2.
But you can also get into trouble the other way around.
If you for example have
⢠plugin A in the settings script classpath classloader
⢠plugin B in the root project classpath classloader
⢠plugin A has some code like pluginManager.withPlugin("B") { configure<ExtensionOfA> { ... } }
, then this will again fail, because A reacts to B being applied by its String ID like it is recommended by Gradle folks, but then when it tries to use the extension class of A it fails, because that class is on the root project classloader which is a child classloader and cannot be seen by the settings classloader. So if you had a compileOnly
dependency on B which most often makes sense with such code, you get a class not found exception. If you badly had an implementation
dependency, you get a class cast exception stating that you cannot cast ExtensionOfA
to ExtensionOfA
, because it gets an instance of the class on the root project classloader and tries to cast it to the class on the settings classloader.
.......
What I usually do is not to try to prematurely fix an issue that I might not have.
I try to write the build nicely, and if I have a problem which requires that I put things on common classloaders, then I do it.
(If I did not anyway put the build logic in an included build that depends on all plugins and thus resolved the problem at the root already š)Clayton Walker
03/31/2025, 11:56 PMClayton Walker
03/31/2025, 11:59 PMClayton Walker
04/01/2025, 12:01 AMVampire
04/01/2025, 12:12 AMClayton Walker
04/01/2025, 1:01 AMClayton Walker
04/01/2025, 2:36 PM