I’ve made a custom gradle Plugin, Task and BuildService.
The plugin registers the service and the tasks has a @ServiceReference.
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':float-main-app:generate' (type 'TransmTask').
- In plugin 'com.bitwig.trans_m.TransmPlugin_Decorated' type 'com.bitwig.trans_m.TransmTask' property 'loaderService' doesn't have a configured value.
Reason: This property isn't marked as optional and no value has been configured.
Possible solutions:
1. Assign a value to 'loaderService'.
2. Mark property 'loaderService' as optional.
For more information, please refer to https://docs.gradle.org/9.1.0/userguide/validation_problems.html#value_not_set in the Gradle documentation.
* Try:
> Assign a value to 'loaderService'
> Mark property 'loaderService' as optional
> Run with --scan to generate a Build Scan (Powered by Develocity).
Do you have an idea what could lead to this property not being provided by gradle?
Yeah, you probably applied the plugin to sibling projects.
The first project that is configured adds a build service with the name.
The second project that is configured sees that a build service with that name is already registered.
The problem is, only if the classpaths of both project build scripts are identical the same classloader is used.
If there is any difference they have separate classloaders and thus the build service classes are different as they are from different classloaders.
By adding it to the root buildscript classloader the subprojects use the classes from there because the root project buildscript classloader is in the ancestry of the subproject classloaders and usual classloader loading hierarchy applies, so in that case both projects see the same service class instance and thus the injecting works which previously failed due to different class instance.