在settings.gradle.ktl上未解析的Kotlin DSL参考 [英] Kotlin DSL Unresolved reference on settings.gradle.ktl

查看:71
本文介绍了在settings.gradle.ktl上未解析的Kotlin DSL参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从buildSrc模块中引用变量时,在settings.gradle.kts上收到未解决的参考构建错误.

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

奇怪的是,当我使用buildSrc中的变量时,例如在应用程序级别build.gradle.kts中,一切正常.

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.

将gradle版本从6.5更改为5.6.4似乎可以解决问题,但我不喜欢这种方法.

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

推荐答案

在Gradle 5.6中不建议使用设置脚本中的 buildSrc 访问定义.

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

从文档中: https://docs.gradle.org/current/userguide/upgrading_version_5.html#classes_from_buildsrc_are_no_longer_visible_to_settings_scripts

以前,buildSrc项目是在应用项目的设置脚本及其类在脚本.现在,buildSrc是在设置脚本及其设置之后构建的类对它不可见.buildSrc类仍然对可见项目构建脚本和脚本插件.

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.

您将必须对在 buildSrc 中定义的字符串值进行硬编码,并将其写入 settings.gradle.kts 中.

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

这篇关于在settings.gradle.ktl上未解析的Kotlin DSL参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆