build.gradle.kts:10:28: Unresolved reference: settings

Viewed 992

I have seen examples for using "by settings" delegation in build.gradle.kts scripts, but no matter what I have tried to do, Gradle complains that settings is an unresolved reference. If I change 'settings' to 'project', Gradle is happy. Has the use of 'by settings' been deprecated? I looked in the Gradle 6.4.1 manual and it shows this delegation. I've attached an image showing a simple Spring Boot app generated by Initializr with the only changes being the addition of the gradle.properties file and the delegation in the build.gradle.kts file. I'd really appreciate any hints about this issue... I know that I can use 'extra' properties or finding the property against the project object, but, frankly, this issue has annoyed me to the point that I need to know what is wrong! :P. Thank you for any help...

enter image description here

1 Answers

The project delegate is defined in the class ProjectDelegate. Your build script is evaluated against an instance of KotlinBuildScript which extends Project, so the delegate is available.

However, when settings.gradle is evaluated, projects aren't configured yet, so there's no instance of KotlinBuildScript. Instead, the script is evaluated against an instance of KotlinSettingsScript which extends Settings, which has the settings delegate. I don't think this delegate was ever available to project build scripts.

In both cases the delegate is provided by an extension function, because both Project and Settings are Java files part of the Gradle core API.

I hope that answers your question.

Related