kotlin - 使用额外属性的 build.gradle.kts 脚本中的错误

标签 kotlin gradlew

下面是一个小的 (build.gradle.kts) 脚本,它在第 9 行(类路径行)给出错误:无法在额外的属性扩展上获取属性“kotlinVersion”,因为它不存在

buildscript {
    extra["kotlinVersion"] = "1.2.70"

    repositories {
        jcenter()
    }

    dependencies {
      classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlinVersion"]}")
    }
}

我不明白为什么会出现这个错误。

最佳答案

这对我有用:

buildscript {
    extra["kotlin_version"] = "1.3.61"

    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.3")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${extra["kotlin_version"]}")
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

关于kotlin - 使用额外属性的 build.gradle.kts 脚本中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60205104/

相关文章:

java - Gradle 命令行传递 org.gradle.jvmargs

Android:找不到或加载主类 org.gradle.wrapper.GradleWrapperMain

java - 如何让gradlew.bat自动运行任务?

android - 使用 null 数组而不是可选数组

dictionary - 在函数中从 Hashmap 正确返回 Int

android - Gradle 错误 : Write access is allowed from event dispatch thread only in Android Studio

gradle - 将项目 jar 和外部 jar 上传到本地 maven 存储库

android - 我应该在 Dagger2 和 Kotlin 中使用 @Singleton、对象还是两者?

android - Kotlin Android 共享首选项 - lateinit 属性首选项尚未初始化

java - E/BitmapFactory : Unable to decode stream: java. io.FileNotFoundException(没有这样的文件或目录)