Gradle’s Kotlin DSL BuildSrc

nwillc
The Startup
Published in
3 min readApr 12, 2020

--

I’ve used Gradle for years and jumped on the Kotlin DSL as soon as it was offered. Switching to the Kotlin DSL wasn’t trivial at first, sometimes finding a Kotlin path through the Groovy ecosystem required digging. The benefits were quick and clear however. Build files were simpler, easier to read, and more maintainable. One new features I was slow to jump on was the buildSrc folder. I’d been curious about it but until I stumbled on this article I just didn’t see a pressing need.

What Is BuildSrc And Why it’s Worth a Look?

If a buildSrc folder is present in your project, gradle “automatically compiles and tests this code and puts it in the classpath of your build script.” Most of the descriptions around buildSrc are focused on performance and dealing with complex projects. But any project can benefit from buildSrc. Why? Gradle’s build script processing order, with the buildscript being processed before things like the gradle.properties, meant it was tricky to uniformly define constants for things like dependency versions so they could be used in the buildscript, plugins, and dependencies stanzas. Now there’s code available before anything happens — awesome!

Let’s Use BuildSrc to Organize Constants And Dependencies

--

--

nwillc
The Startup

Graybeard code monkey, started on an Apple IIe, got a CS degree in the 80’s, and coded my way through C, C++, Objective-C, Java, Kotlin — and now Go.