Can't use project extra properties in plugin block

旧时模样 提交于 2019-12-01 19:03:10

According to documentation (see Constrained syntax subsection)

«plugin version» and «plugin id» must be constant, literal, strings

There are some other notes related to your question in the following paragraphs:

The plugins {} block must also be a top level statement in the buildscript. It cannot be nested inside another construct (e.g. an if-statement or for-loop).

Can only be used in build scripts

The plugins {} block can currently only be used in a project’s build script. It cannot be used in script plugins, the settings.gradle file or init scripts.

Future versions of Gradle will remove this restriction.

So it is not possible to do this now.

There is a workaround to extract the plugin version and use it afterwards, but I personally find it ugly and prefer using explicit versions.

build.gradle.kts root

buildscript {
  val kotlinVersion by rootProject.extra { "1.3.10" }
  ...
}

build.gradle.kts module

dependencies {
  implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${rootProject.extra.get("kotlinVersion")}")
}

Official docs

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