0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · Lesson

Custom Repositories & BOMs

Configure custom Maven or Ivy repositories and use Bill of Materials (BOMs) for consistent dependency versions.

Custom Repositories & BOMs is a free Groovy & Gradle: JVM Automation and Build Engineering lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Groovy & Gradle: JVM Automation and Build Engineering learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Beyond Maven Central

By default, Gradle looks for dependencies in Maven Central. But what if your dependencies aren't there?

Custom repositories allow you to fetch libraries from other locations, like:

  • Your company's private artifact server.
  • Specific public repositories (e.g., Google's Maven repo for Android).
  • Local file system directories.

Adding a Maven Repository

To add a custom Maven repository, you declare it in the repositories block of your build.gradle file.

Gradle will check repositories in the order they are declared, stopping at the first match.

repositories {
    mavenCentral()
    maven {
        url 'https://repo.spring.io/milestone'
    }
}

Example: Google Maven Repo

Many Android libraries are hosted on Google's Maven repository. You'd add it like this:

This is crucial for projects using Google-specific libraries.

repositories {
    google() // Shortcut for Google's Maven repo
    mavenCentral()
}

Understanding Ivy Repositories

While Maven is very common, Gradle also supports Ivy repositories. Ivy has a more flexible layout for artifacts.

You might encounter Ivy repositories in older projects or specific corporate environments.

repositories {
    ivy {
        url "http://repo.mycompany.com/ivy"
        layout "pattern", {
            artifact "[organization]/[module]/[revision]/[artifact](-[classifier])-[revision].[ext]"
        }
    }
}

Local Directory as Repo

For testing or internal use, you can even use a local directory as a repository. This is handy for sharing artifacts within a team without a dedicated server.

Just specify the path to your local folder.

repositories {
    flatDir {
        dirs 'libs' // Looks for JARs directly in the 'libs' folder
    }
    // Or a more structured Maven-like local repo
    maven {
        url uri('../my-local-maven-repo')
    }
}

Bill of Materials (BOMs)

A Bill of Materials (BOM) is a special Maven POM file that defines a curated list of dependency versions.

It helps manage transitive dependencies and ensures consistent versions across a multi-module project or when using a suite of related libraries.

Consistency with BOMs

BOMs solve a common problem: dependency version conflicts. If multiple libraries depend on different versions of the same transitive dependency, you can end up with unpredictable behavior.

With a BOM, you declare a single "source of truth" for versions, making your build more reliable.

Importing a BOM

To use a BOM in Gradle, you declare it as a dependency using the platform() or enforcedPlatform() function. This tells Gradle to use the versions specified in the BOM.

Notice how we don't specify versions for spring-core or spring-web; the BOM handles it!

dependencies {
    implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.5')

    // These versions are now managed by the BOM
    implementation 'org.springframework:spring-core'
    implementation 'org.springframework:spring-web'
}

Platform vs. EnforcedPlatform

There are two ways to import a BOM:

  • platform(): Suggests versions. Other modules can override these versions if explicitly declared.
  • enforcedPlatform(): Strictly enforces versions. Any explicitly declared versions for dependencies in the BOM will be overridden by the BOM's version.

Use enforcedPlatform() for strong version consistency.

Check Your Knowledge

Let's test your understanding of custom repositories and BOMs!

Custom Repos & BOMs Recap

Great job! You've learned how to:

  • Configure custom Maven and Ivy repositories in Gradle.
  • Understand the importance of repository order.
  • Use local directories as repositories.
  • Leverage Bill of Materials (BOMs) for consistent dependency version management.
  • Differentiate between platform() and enforcedPlatform().

These techniques are vital for managing complex dependency landscapes in real-world projects!

Frequently asked questions

Is the “Custom Repositories & BOMs” lesson free?

Yes — the full text of “Custom Repositories & BOMs” is free to read here on the web, and the Groovy & Gradle: JVM Automation and Build Engineering course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Groovy & Gradle: JVM Automation and Build Engineering course, upgrade to CoddyKit PRO.

What will I learn in “Custom Repositories & BOMs”?

Configure custom Maven or Ivy repositories and use Bill of Materials (BOMs) for consistent dependency versions. You practise Groovy & Gradle: JVM Automation and Build Engineering with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Groovy & Gradle: JVM Automation and Build Engineering?

No prior experience is required. Groovy & Gradle: JVM Automation and Build Engineering on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Custom Repositories & BOMs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Groovy & Gradle: JVM Automation and Build Engineering lesson?

Yes. Every Groovy & Gradle: JVM Automation and Build Engineering lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Declaring Project Dependencies
  2. Dependency Resolution & Caching
  3. Custom Repositories & BOMs
  4. Resolving Version Conflicts & Dependency Constraints
← Back to Groovy & Gradle: JVM Automation and Build Engineering