简体   繁体   English

如何将保护级别 build.gradle 的文件从 Gradle Groovy 迁移到 Gradle Kotlin DSL

[英]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.

相关问题 如何在 Android Studio Bumblebee 中将 build.gradle 从 Groovy 迁移到 Kotlin DSL? - How to Migrate build.gradle from Groovy to Kotlin DSL in Android Studio Bumblebee? 如何从 Kotlin DSL build.gradle 中的所有依赖项中排除库? - How to exclude library from all dependencies in Kotlin DSL build.gradle? 如何为子项目或应用程序级别指定 gradle 版本 build.gradle - How to specify gradle version for subprojects or app level build.gradle 找不到Gradle DSL方法:'compile()'-依赖项已在模块级别build.gradle中 - Gradle DSL method not found: 'compile()' - Dependencies are in Module level build.gradle already 从 build.gradle 文件以编程方式创建 gradle 文件 - Create gradle file programmatically from build.gradle file 从build.gradle运行gradle命令 - Run a gradle command from build.gradle 从build.gradle(Module)中提取通用代码到顶层build.gradle(Project) - Common code from build.gradle(Module) extract into top-level build.gradle(Project) build.gradle如何应用另一个文件的闭包 - build.gradle how to apply a closure from another file 如何在build.gradle中更改.java文件中的某些值? - How to change some value in .java file from build.gradle? 如何从 build.gradle 配置变量? - How to configure a variable from build.gradle?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM