Skip to content

Steve Hill

How Do I Migrate My Gradle Dependencies To Be Transitive?

java, build, code1 min read

Background

We're using gradle as a build tool and for managing dependencies on our Java-based project. The project is multi-module, with one parent build.gradle file and each module (subproject) having its own build.gradle file.

Problem

The parent build.gradle defines an ivy repository with a maven layout for each of the subprojects. Transitive dependencies don't resolve with this configuration, so most of the transitives are required individually. We'd like to change it to simply be a maven repository and have dependencies transitively resolved - cutting out about 50% of our build file - but that causes many conflicts.

Solution

Migrate piecemeal. In each subproject, we can define the same repository url as a maven repository, and transitive resolution will work for that project only. Once this is done for all the children, the parent can be switched to a maven repository and we can delete the old ivy repository.

Example parent build.gradle:

1subprojects {
2 repositories {
3 ivy {
4 layout 'maven'
5 url 'path://to/my/maven/repo'
6 }
7 }
8}

Example child build.gradle:

1repositories {
2 maven {
3 url 'path://to/my/maven/repo'
4 }
5}

Gotchas

Watch out for projects that depend on other projects. If A depends on B, and you make B transitively resolved first, A will not compile. It's most effective (and least painful) to start making the outermost projects transitive first.