Kotlin DSL Unresolved reference on settings.gradle.ktl

空扰寡人 提交于 2021-01-28 14:41:30

问题


I am getting an unresolved reference build error on settings.gradle.kts when I am referencing variables from the buildSrc module.

The strange thing is that when I am using the variables from buildSrc, for example to the app level build.gradle.kts, everything works fine.

Also the error occurs only when I build/sync and I am not getting that error(red highlights) on the text editor and the navigation to that variable works fine.

Attached you find an image with the setup, thanks a lot.

Edit: Changing gradle version from 6.5 to 5.6.4 seems to fixed the problem, but I do not like that approach.


回答1:


Accessing definitions from buildSrc in settings scripts was deprecated in Gradle 5.6.

From the docs: https://docs.gradle.org/current/userguide/upgrading_version_5.html#classes_from_buildsrc_are_no_longer_visible_to_settings_scripts

Previously, the buildSrc project was built before applying the project’s settings script and its classes were visible within the script. Now, buildSrc is built after the settings script and its classes are not visible to it. The buildSrc classes remain visible to project build scripts and script plugins.

You would have to hardcode those string values defined in your buildSrc and write them in your settings.gradle.kts.



来源:https://stackoverflow.com/questions/62996848/kotlin-dsl-unresolved-reference-on-settings-gradle-ktl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!