How in buildSrc use project() instead of const string, Gradle Dependency Management with Kotlin

200 Views Asked by At

I use const string in my project, like here: https://handstandsam.com/2018/02/11/kotlin-buildsrc-for-better-gradle-dependency-management. In my build.gradle.kts my dependencies block looks like:

dependencies {
    compile(project(DepModule.cmn))
    compile(project(DepModule.logs))
   .......
}

How use in dependencies block compile(DepModule.cmn) instead of compile(project(DepModule.cmn))? And is it possible so?

1

There are 1 best solutions below

0
On

If you use Kotlin in your buildSrc, you can write the following:

object DepModule {
    val DependencyHandler.cmn get() = project(":module:common")
}

and then access in build.gradle.kts like so:

dependencies {
    compile(DepModule.cmn)
}

I'm not sure if this trick with extension properties will work with Groovy.