Did you know you can write Kotlin in a module named buildSrc to manage your dependencies in your Gradle files?
How? When you run Gradle, it checks for the existence of a directory called buildSrc. Gradle then automatically compiles this code and puts it in the classpath of your build script. You don’t need to provide any further instruction.
It may not seem like it’s that big of a deal, but managing Gradle dependencies is a pain, and getting to use Kotlin and having autocomplete in Android Studios is a game changer.
Hi Sam, Great lesson do we get the warning when a newer version of a library is available using buildSrc ?
to add to this thread - I also faced a similar thing when using this in my projects. One thing that we setup was a notifier on our CI service that prints out-of-date libraries onto any pull requests that are opened (I wrote this up here https://overflow.buffer.com/2018/10/26/keeping-check-on-your-android-libraries-with-danger-bitrise/). If you're not using a CI service then in the article there is also the mention of a gradle plugin that can be run locally to check for out of date libraries - a bit more manual but still helps detect library versions that need updating!
In fact, I am starting a new project after completing your excellent course on clean architecture. I was looking for a better way to handle the dependencies and I found Sam's lesson. During the whole course, I was using "ben-manes/gradle-versions-plugin", for tracking new library versions using the command in the terminal. I think its time for me to create CI service, I am using Gitlab I hope I can replicate what you did in Bitrise.
You're not the only one that has had this question. The answer is that currently the upgrade warning won't display with the buildSrc technique. I didn't realize this limitation until later on after publishing this content. Here is a Github issue with some discussion about it: https://github.com/handstandsam/AndroidDependencyManagement/issues/6. I'll work on making sure that we have an issue filed with Google and can update that Github Issue thread once I've either:
1) located the issue someone else has reported, or
2) reported it myself.
Regardless of this small limitation currently, I've had a lot of success on the projects where I've used this technique and am continuing to use it and do even more with code in buildSrc beyond this.
I will follow the thread and will use buildSrc with a CI service as Joe suggested.