[英]How to migrate protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL
I'm trying to migrate my protect level build.gradle file from Gradle Groovy to Gradle Kotlin DSL.我正在尝试将我的保护级别 build.gradle 文件从 Gradle Groovy 迁移到 Gradle Kotlin DSL。 I've watched several tutorials but none of them clearly explain what to change the code to in the project level
build.gradle
file.我看过几个教程,但都没有清楚地解释将项目级别
build.gradle
文件中的代码更改为什么。 I only got as far as renaming the file to build.gradle.kts
.我只是将文件重命名为
build.gradle.kts
。
Error错误
Unresolved reference.
未解决的参考。 None of the following candidates is applicable because of receiver type mismatch: public infix fun PluginDependencySpec.version(version: String?): PluginDependencySpec defined in org.gradle.kotlin.dsl public infix fun PluginDependencySpec.version(version: Provider): PluginDependencySpec defined in org.gradle.kotlin.dsl
由于接收器类型不匹配,以下候选者均不适用: public infix fun PluginDependencySpec.version(version: String?): PluginDependencySpec defined in org.gradle.kotlin.dsl public infix fun PluginDependencySpec.version(version: Provider): PluginDependencySpec defined in org .gradle.kotlin.dsl
buildscript {
ext {
compose_version = "1.1.1"
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application" version "7.3.1" apply false)
id("com.android.library" version "7.3.1" apply false)
id("org.jetbrains.kotlin.android" version "1.6.10" apply false)
}
Change to:改成:
id("com.android.application") version "7.3.1" apply false
Explanation:解释:
version
is defined as infix fun PluginDependencySpec.version(version: String)
, so it can be called as id("...").version("...")
or as id("...") version "..."
but it cannot called on String
version
被定义为中infix fun PluginDependencySpec.version(version: String)
,因此它可以被称为id("...").version("...")
或id("...") version "..."
但它不能调用String
in your invalid code:在您的无效代码中:
id( "com.android.application" /*String*/ version /*??? no String.version*/ "7.3.1" apply false )
but valid:但有效:
id( "com.android.application") /*PluginDependencySpec*/ version /*OK PluginDependencySpec.version*/ "7.3.1" apply false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.