当我尝试在Gradle 7.0中使用目录功能时https://docs.gradle.org/7.0.2/userguide/platforms.html#sub:central-declaration-of-dependencies
如下所示,转换为setting.gradle
dependencyResolutionManagement {
// Some other codes
versionCatalogs {
libs {
alias('androidx-core').to('androidx.core:core-ktx:1.6.0')
alias('androidx-appcompat').to('androidx.appcompat:appcompat:1.3.1')
alias('androidx-constrainlayout').to('androidx.constraintlayout:constraintlayout:2.1.0')
alias('android-material').to('com.google.android.material:material:1.4.0')
}
}
}
当我执行gradle同步时,它错误地指出
Caused by: org.gradle.api.InvalidUserCodeException: Using dependency catalogs requires the activation of the matching feature preview.
我检查了https://docs.gradle.org/7.0.2/userguide/platforms.html#sub:central-declaration-of-dependencies,发现它指出
Central declaration of dependencies is an incubating feature. It requires the activation of the VERSION_CATALOGS feature preview.
在https://docs.gradle.org/7.0.2/userguide/feature_lifecycle.html#feature_preview网站上
The feature preview API allows certain incubating features to be activated by adding enableFeaturePreview('FEATURE') in your settings file. Individual preview features will be announced in release notes.
我尝试在settings.gradle
中添加enableFeaturePreview('FEATURE')
,但似乎不起作用。我应该把enableFeaturePreview('FEATURE')
放在哪里?
2条答案
按热度按时间htrmnn0y1#
看起来我需要将
FEATURE
替换为实际功能的名称。即我只是把它放在
settings.gradle
文件的第一行,这就可以了。sqougxex2#
在我的例子中,当我在
settings.gradle (project-name)
文件的最后一行中添加enableFeaturePreview("VERSION_CATALOGS")
行时,它可以工作。文件是
settings.gradle(项目名称)
和build.gradle(项目名称)