英文:
Kotlin DSL migration project gradle build
问题
我正在迁移到Kotlin DSL
这是我的项目级别的build.gradle文件
// 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
plugins {
id("com.android.application") version "7.2.2" apply false
id("com.android.library") version "7.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.7.10" apply false
}
task<Delete>("clean") {
delete(rootProject.buildDir)
}
我已将文件扩展名更改为build.gradle.kts
文件内容更改为
plugins {
id("com.android.application") version "7.2.2" apply false
id("com.android.library") version "7.2.2" apply false
id("org.jetbrains.kotlin.android") version "${Versions.kotlin}" apply false
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
我遇到了以下错误
未解析的引用。由于接收器类型不匹配,以下候选项中没有一个适用于:
public infix fun PluginDependencySpec.version(version: String?): PluginDependencySpec defined in org.gradle.kotlin.dsl
public infix fun PluginDependencySpec.version(version: Provider<String>): PluginDependencySpec defined in org.gradle.kotlin.dsl
英文:
I am migrating to kotlin DSL
And this is my project level build gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.2' apply false
id 'com.android.library' version '7.2.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I updated the file extension to -build.gradle.kts
And the file content to
plugins {
id ("com.android.application" version "7.2.2" apply false)
id ("com.android.library" version "7.2.2" apply false)
id ("org.jetbrains.kotlin.android" version "${Versions.kotlin}" apply false)
}
tasks.register("clean",Delete::class){
delete(rootProject.buildDir)
}
I am getting this 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<String>): PluginDependencySpec defined in org.gradle.kotlin.dsl
答案1
得分: 1
更新插件块如下:
plugins {
id("com.android.application") version "7.2.2" apply false
id("com.android.library") version "7.2.2" apply false
id("org.jetbrains.kotlin.android") version "${Versions.kotlin}" apply false
}
此外,我认为clean
任务默认可用,无需手动创建。
在迁移时,您还可以考虑迁移到版本目录。请参考NowInAndroid应用程序源代码。
英文:
Update the plugins block as follows:
plugins {
id ("com.android.application") version "7.2.2" apply false
id ("com.android.library") version "7.2.2" apply false
id ("org.jetbrains.kotlin.android") version "${Versions.kotlin}" apply false
}
Also, I think the clean
task is available by default. You do not need to create it manually.
You can also consider migrating to Version Catalog while you are migrating. Please follow the NowInAndroid app source code for that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论