Have you ever wanted to write an extension fonctio...
# gradle
j
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
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
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:
Copy code
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" , ...)