Applying buildSrc plugin to settings

Hey, this is an older post and most links don’t work anymore but it seems that I have the same problem.

I created a Gradle project, added builcSrc and created an example plugin in there. First I created it with gradle init but I tried to remove everything that is not required, so only buildSrc/build.gradle and buildSrc/src/main/java/org/example/MypluginPlugin.java remain.
I added the plugin to my plugins block in my main project but now it fails:

Calculating task graph as no cached configuration is available for tasks: clean

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\src\gradlebuildsrcplugin\settings.gradle' line: 11

* What went wrong:
Plugin [id: 'my-plugin'] was not found in any of the following sources:

- Gradle Core Plugins (not a core plugin. For more available plugins, please refer to https://docs.gradle.org/8.14.2/userguide/plugin_reference.html in the Gradle documentation.)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (plugin dependency must include a version number for this source)

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
Configuration cache entry stored.

According to 4. Applying convention plugins from the buildSrc directory this should work, shouldn’t it?

Here is my project: cwansart/gradle-buildsrc-plugin-test - Codeberg.org

After reading Writing Plugins I created a Groovy-based plugin which work, see: Making sure you're not a bot!
But I am not sure why the other example does not work.

I don’t think your issue is too closely related to that ancient topic, so I moved it to is own thread.

You problem simply is, that buildSrc is built after the settings script is evaluated, so you cannot provide a settings plugin in buildSrc. If you instead use an included build, it works, as those can also provide settings plugins.

1 Like

@Vampire I was able to fix it by moving id 'my-plugin' into build.gradle of my main project. I just put it into settings.gradle for testing purposes.

You mean I need to use includeBuild('buildSrc') in my settings.gradle?

Edit: I think I found it: Composite Builds

Project plugins you can have in an included build or in buildSrc.
Settings plugins you can only have in an included build.
The included build would need to be called differently as the name buildSrc is reserved for that special construct that is quite similar to an included build but has some subtle differences.

And yes, if you include a build, you get a composite build as result.

1 Like