Kotlin DSL迁移项目gradle构建

huangapple go评论60阅读模式
英文:

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 &#39;com.android.application&#39; version &#39;7.2.2&#39; apply false
    id &#39;com.android.library&#39; version &#39;7.2.2&#39; apply false
    id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.7.10&#39; 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 (&quot;com.android.application&quot; version &quot;7.2.2&quot; apply false)
id (&quot;com.android.library&quot; version &quot;7.2.2&quot; apply false)
id (&quot;org.jetbrains.kotlin.android&quot; version &quot;${Versions.kotlin}&quot; apply false)
}

tasks.register(&quot;clean&quot;,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&lt;String&gt;): 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 (&quot;com.android.application&quot;) version &quot;7.2.2&quot; apply false
    id (&quot;com.android.library&quot;) version &quot;7.2.2&quot; apply false
    id (&quot;org.jetbrains.kotlin.android&quot;) version &quot;${Versions.kotlin}&quot; 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.

huangapple
  • 本文由 发表于 2023年6月8日 17:23:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430385.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定