Darkin Rall
Darkin Rall

Reputation: 459

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

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?

Upvotes: 0

Views: 211

Answers (1)

Dominik Murzynowski
Dominik Murzynowski

Reputation: 345

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.

Upvotes: 0

Related Questions