Here ‘nonnull’ is my custom plugin. I get the following on attempt to build from a root project dir:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/denis/project/java/xxx/build.gradle' line: 31
* What went wrong:
A problem occurred evaluating root project 'search'.
> Plugin with id 'nonnull' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.269 secs
Note that here line 31 mentioned at the error message is a line with text “apply plugin: ‘nonnull’”.
The problem is fixed if I add the same buildscript initialization at the root project:
It seems that the problem is that root project is unaware of my custom plugin but it’s not clear why does it try to evaluate it at all because the plugin appliance statement is located at ‘subprojects’ block. Tried to google the answer but no luck so far. Any ideas?
I think the problem is different, namely that ‘buildscript’ needs to be top-level and cannot be nested inside ‘subprojects’. (‘buildscript’ is very special; it gets extracted from the build script before compiling/evaluating the script.) Hence your nested ‘buildscript’ block doesn’t have any effect, but the one for the root project also affects subprojects (due to Gradle’s current class loader hierarchy).
Btw, /unrelated to the thread’s question/ is it possible to get a classloader which knows either about compiled project source classes or project binary dependencies (including transitive)? It looks like defining classloader for plugin’s class is aware only of compiled project source classes
Thank you for the advice but it seems I was not clear enough. Basically, I need to get a classloader which is backed by the same classpath as the one used during compilation
I’d recommend to create a class loader based on ‘sourceSets.main.compileClasspath’. This is the “source of truth” and defaults to ‘configurations.compile’ (but is sometimes reconfigured). Depending on what you are doing, you might also have to take other source sets into account, e.g. ‘test’ or a manually declared source set.