Gradle 8 project dependency requirement clarification

Hello,

I recently upgraded a Gradle project from version 4.2 to 8.1.1. This was done in step-by-step manner, upgrading subsequently from one major version to the next(i.e., 4 → 5, 5 → 6, etc.), ensuring the project remained building successfully at each iteration.
Moving from Gradle 6 to 7, I noticed the following change in explicit dependency requirements:

Before the upgrade - Implicit dependency supported
MyProject is a gradle project with subprojects A, B, and C:

subproject B: declare dependency on A

*myProject/B/build.gradle*
dependencies {
    compile(project(":A"))
}

subproject C: declare dependency on B

*myProject/C/build.gradle*
dependencies {
    compile(project(":B"))
}

As a result of the above it is observed that C will have dependency on A automatically without having to explicitly state it in C’s build script.

After the upgrade - Implicit dependency no longer appears supported

subproject B: declare dependency on A

*myProject/B/build.gradle*
dependencies {
    implementation(project(":A"))
}

subproject C: declare dependency on B
But also it is observed that C must explicitly declare dependency on A for the build to not fail

*myProject/C/build.gradle*
dependencies {
    implementation(project(":B"))
    implementation(project(":A"))
}

Looking through the Gradle docs I was unable to find any information in support of this now being a requirement in the more recent versions of Gradle. Is this behaviour expected, and if so what is the reasoning behind it?

Thank you!

This is expected and specifically the whole reason for the change from compile to implementation. There are benefits to being explicit about the dependencies that a project has vs. those that are only an implementation detail. If you want a dependency to be more than just an internal implementation detail to the consumers, implementation is not the right configuration to declare for the dependency. This is discussed briefly in Understanding the difference between libraries and applications and then in more detail in The Java Library Plugin.

2 Likes

James’ answer implies, that your “note” means that you had compile in the before code, which is the only situation that makes any sense. Because how you described it, it would be a bug. But if you had implementation in 6 already, you would have had the same behavior already. So I suggest you edit your question to “remove the simplification” you mentioned in the note as it actually make the question invalid. :smiley:

1 Like

That is correct, I did have compile before and I see now how my attempt at simplifying the flow of my question does not make sense. I have made the correction now, thanks for the clarification!

Thank you for clearing this up for me James!