How to configure gradle rule base model plugin in gradle kotlin DSL?

Viewed 141

I'm using play-application plugin, which in turn use gradle rule based model configuration. build.gradle.kts looks like this:

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)

where play_setup.gradle is:

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

Is there a way to stop using groovy for plugins made with rule based model and configure them directly via kotlin-DSL?

1 Answers

Not according to the limitations listed in the Gradle Kotlin DSL Primer.

The Kotlin DSL will not support the model {} block, which is part of the discontinued Gradle Software Model. However, you can apply model rules from scripts — see the model rules sample for more information

The link to the model rules sample is broken in the documentation, but I fixed it above.

Related