ext in buildscript can not be recognised by Gradle Kotlin DSL

只谈情不闲聊 提交于 2019-12-03 01:24:21

With Kotlin DSL ext has been changed to extra and it can be used under buildscript.

Eg :-

buildscript {
    // Define versions in a single place
    extra.apply{
        set("minSdkVersion", 26)
        set("targetSdkVersion", 27)
    }
}

What is working for me is using ext in allprojects instead of buildscript, so in your top-level build.gradle.kts

allprojects {
  ext {
    set("supportLibraryVersion", "26.0.1")
  }
}

then you can use it in build.gradle.kts files in modules like this:

val supportLibraryVersion = ext.get("supportLibraryVersion") as String

Global properties in kotlin-gradle-dsl:
https://stackoverflow.com/a/53594357/3557894


Kotlin version is embedded into kotlin-gradle-dsl.
You can use dependecies with embedded version as follows:

implementation(embeddedKotlin("stdlib-jdk7"))

classpath(embeddedKotlin("gradle-plugin"))

There is a new possibility with Kotlin we can use:

object DependencyVersions {
    const val JETTY_VERSION = "9.4.12.v20180830"
}

dependencies{
    implementation("org.eclipse.jetty:jettyserver:${DependencyVersions.JETTY_VERSION}")
}

Here, DependencyVersions is a name I chose. You can choose another name, like "MyProjectVariables". This is a way to avoid using the extra or ext properties.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!