Adding a configuration directory to the plugins classpath


I am trying to add an external directory of configuration files to the Gradle plugins classpath so that one of my plugins can do the following:


To that end, I have created this file in my project directory:


and added this buildscript to my build.gradle:

buildscript {
    dependencies {
        classpath files('repository')

However, my plugin is consistently failing to find my resource file. Is the buildscript classpath invisible from the plugins classpath? Because I am expecting its classloader to be one of the plugins classloader’s parents.

Thanks for any insights here,

P.S This example project is using Gradle 6.7.1 and Gradle’s test kit.

Could this just be a failing in the Gradle Test Kit? I am starting to suspect that the GradleRunner does not augment the plugins classpath with anything from the buildscript classpath.

I’ve tried adding buildSrc.jar to GradleRunner via logic resembling:

runner.withPluginClasspath(File("buildSrc/build/libs/buildSrc.jar") + runner.pluginClasspath)

but this doesn’t work either :man_facepalming:. I can only assume that the Gradle Test Kit just doesn’t support this.

I think I’ve finally managed to resolve this by wrapping my configuration file inside its own Gradle plugin. This allows me to perform :sparkles: magic :sparkles: like this:

project.getPluginManager().withPlugin(plug -> {
    Class<? extends Plugin> pluginClass = project.getPlugins().getPlugin(plug.getId()).getClass();

provided my new plugin’s Plugin implementation lives in the same package as its configuration file.