如何在Gradle Kotlin DSL中配置Gradle规则基础模型插件?

时间:2018-08-29 05:20:27

标签: gradle gradle-kotlin-dsl

我正在使用play-application插件,该插件又使用基于gradle规则的模型配置。 build.gradle.kts看起来像这样:

plugins {
    `play-application`
}

/* the snippet does not work
  model {
    components {
      play {
        platform play: playVersion, scala: scalaVersion, java: javaVersion
        injectedRoutesGenerator = true
      }
    }
  }
*/

// this works instead
apply(from = "play_setup.gradle")
val setup: groovy.lang.Closure<Any?> by extra
setup(project, jVersion, scalaVersion, playVersion)

其中play_setup.gradle是:

ext.setup = { project, javaVersion, scalaVersion, playVersion ->
  model {
    components {
      play {
        platform play: playVersion, scala: scalaVersion, java: javaVersion
        injectedRoutesGenerator = true
      }
    }
  }
}

是否有办法停止对基于规则的模型制作的插件使用groovy并直接通过kotlin-DSL对其进行配置?

1 个答案:

答案 0 :(得分:1)

不符合Gradle Kotlin DSL入门中列出的limitations

Kotlin DSL将不支持model {}块,该块是 discontinued Gradle Software Model。但是,您可以应用模型 脚本中的规则-有关更多信息,请参见model rules sample

文档中指向模型规则示例的链接已断开,但我已在上面对其进行了修复。