https://kotlinlang.org logo
Title
j

jmfayard

10/19/2018, 11:32 AM
Have you ever wanted to write an extension fonction like
fun  Project.doSomethingCool()
that would also works in a Groovy
build.gradle
file? Have a look at this pattern:
project.kt.doSomethingCool()
https://github.com/jmfayard/gradledemo/commit/896ea008fea9d792d69dad122addc76d09ebce54
🇳🇴 1
n

Nikky

10/19/2018, 1:18 PM
very cool pattern, but i need extension functions inside
compile()
or
plugins()
much more often than on
Project
, any idea how to make those work in groovy ?
in kotlin i can do
compile(ktor("engine-cio"))
for example
j

jmfayard

10/19/2018, 2:07 PM
I mean the thing with Project is that when you have it you can configure everything else in Gradle
I have just used a static function for the thing you requires:
compile(Config.ktor("engine-cio"))

object Config {

    @JvmStatic
    fun ktor(module: String): String {
        require(module in ktorModules) { "Ktor module=$module not in $ktorModules"}
        return "io.ktor:ktor-$module:1.0.0"
    }
    val ktorModules = listOf("server-core", "client-core" , ...)