avatarnwillc

Summary

The web content provides guidance on managing dependencies in growing projects by defining version numbers in gradle.properties and organizing dependencies in a build.gradle file using Kotlin DSL.

Abstract

The provided text discusses best practices for handling dependencies in software projects. It suggests that as projects expand, the number of dependencies increases, and not all of them will be listed in a Bill of Materials (BOM). To maintain order, the author recommends defining dependency versions in the gradle.properties file using the by project syntax. This approach allows for centralized version management. Additionally, the text advises grouping related dependencies in a listOf within the dependencies block of the build.gradle file, which helps in keeping the dependency list clean and reduces repetition when specifying the implementation type for each dependency.

Opinions

  • The author emphasizes the importance of managing dependency versions explicitly to avoid conflicts and ensure consistency across a project.
  • Organizing dependencies using listOf is suggested as a method to enhance readability and maintainability of the build script.
  • The use of forEach to apply a common configuration to multiple dependencies is recommended for brevity and to avoid redundancy.
  • The author's approach implies a preference for centralized management of dependency versions, which can be particularly beneficial in multi-module projects.

Some nice stuff here. Thanks. I’ve a couple of tips I’ll add. As projects grow you’ll end up with a lot of dependencies, and many won’t be in a BOM and will needs versions. So…

val assertJVersion: String by project
val jupiterVersion: String by project
val mockkVersion: String by project
// ...
dependencies {
  listOf(
    "org.junit.jupiter:junit-jupiter-api:$jupiterVersion",
    "org.assertj:assertj-core:$assertJVersion",
    "io.mockk:mockk:$mockkVersion"
  )
    .forEach { testImplementation(it) }
}

First throw versions definitions (i.e. assertJVersion=3.14.0) into your gradle.properties using by project to get them. Second, group dependencies of a type with listOf to keep things tidy and avoid typing the implementation type over and over.

Recommended from ReadMedium