Plugin problems when using multiple build files

Since I don’t like having huge messy files, I divided my build and now it consists of few .gradle files included with apply from in build.gradle.

Recently I started to develop my own plugin that contains a few useful tasks that will be used in more than one project. Problem is that it won’t work correctly with my multiple-file project config.

If I understand correctly, in order to use custom tasks I have to include dependency to my plugin in every included buildscript, but that causes issues with casting, because my classes are loaded many times with different class loaders… So when I had something set as project property it started to cause funny class cast exceptions (cannot cast XY to XY).

As a quick fix I changed few return and argument types to Object. If there is better solution (like loading those classes once and for all)?

Where are you putting your plugin classes?

If you have a single or multi-project build, you could create a buildSrc directory and put your plugin classes there.

If your plugin is external, you need to add your plugin Jar per project (or only to the root project).