buildSrc
is a directory at the project root level which contains build info. We can use this directory to enable
kotlin-dsl
and write logic related to custom configuration and share them across the project. It was one of the most used approaches in recent days because of its testability.
The directory
buildSrc
is treated as an included build. Upon discovery of the directory, Gradle automatically compiles and tests this code and puts it in the classpath of your build script. For multi-project builds, there can be only one
buildSrc
directory, which has to sit in the root project directory.
buildSrc
should be preferred over script plugins as it is easier to maintain, refactor and test the code —
Gradle Docs
as the docs say, in multi-module projects, there is only one buildSrc module and all modules can access it since it is placed in the classpath of build script, seems like a good place to put our Gradle logics to be reused.
Why buildSrc — Kotlin DSL
Compile-Time errors checking
Auto Completion and content assists
Friendly code navigation
Quick documentation (Kotlin function based)
Consistency of using the same language across the application
Enhanced IDE editing experience
Create buildSrc Kotlin Module
The First Step, Create Kotlin Library module name it
buildSrc
.
Now we done. All the Gradle file is now converted to Kotlin.
Conclusion
I highly recommend the “
Kotlin DSL + buildSrc
” option. It may not seem like it’s that big of a deal, but managing Gradle dependencies is a pain, and having autocomplete and click support is a game changer. No more switching back and forth between files manually.
In order to enable some website functionality and provide best possible experience for you, we use cookies. For more information, please review our
Cookie Policy
.