Hello,
the service injection documentation contains an example for injecting ObjectFactory
to retrieve projectDirectory
. This one: https://docs.gradle.org/8.14.2/userguide/service_injection.html#objectfactory (scroll down to the third code box)
I copied the example into my test project but it fails with:
> ./gradlew myInjectedObjectFactoryTask
Calculating task graph as no cached configuration is available for tasks: myInjectedObjectFactoryTask
> Task :myInjectedObjectFactoryTask
C:\src\gradlebuildsrcplugin
[Incubating] Problems report is available at: file:///C:/src/gradlebuildsrcplugin/build/reports/problems/problems-report.html
FAILURE: Build failed with an exception.
* What went wrong:
Configuration cache problems found in this build.
1 problem was found storing the configuration cache.
- Task `:myInjectedObjectFactoryTask` of type `MyObjectFactoryTask`: invocation of 'Task.project' at execution time is unsupported.
See https://docs.gradle.org/8.14.2/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
See the complete report at file:///C:/src/gradlebuildsrcplugin/build/reports/configuration-cache/a74tracg56isg6m6pz6u892yq/3fx1yerwxnjg1158ppqqi5yxl/configuration-cache-report.html
> Invocation of 'Task.project' by task ':myInjectedObjectFactoryTask' at execution time is unsupported.
* 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
8 actionable tasks: 1 executed, 7 up-to-date
Configuration cache entry discarded with 1 problem.
My test project can be found here: https://codeberg.org/cwansart/gradle-buildsrc-plugin-test/src/branch/service_injection/buildSrc/src/main/groovy/my-object-factory-task.gradle
Is this a broken example or did I make a mistake?