We are upgrading projects from the latest 4.x to the latest 5.x. The upgrade process went fine until we built, at which point we got a ton of compiler errors about classes not found. We could see the jars that contain the classes in the dependencies tree, but without adding a number of jars we couldn’t make the errors go away.
Does 5.x fine-grained dependency analysis perhaps wind up generating a smaller tree of dependencies, thereby requiring that more “tops” of the forest be listed?
It didn’t even add dependencies that were in the same tree. For example, one of our jars, let’s call it foo depends on another of our jars, bar. We had foo in the dependencies() section, but didn’t list bar, because in 4.x it automatically figured out that bar was needed by foo. But in 5.x we had to list both foo and bar. We can flip gradlew back and force and reproduce the behavior.
In earlier versions of Gradle, a transitive dependency declared in a POM with runtime scope would be included in the compile classpath. In 5.0 this has changed: only compile scope dependencies are included in the compilation classpath. Dependencies with runtime scope are included in the runtime classpath.
I suspect that this is what’s causing your compilation errors. You can use a Gradle Build Scan or the dependencies report to compare the compileClasspath and runtimeClasspath between the 2 Gradle versions.
In Gradle 4.x, your compileClasspath would contain moduleX.jar, slf4j-api.jar AND slf4j-log4j12.jar. So you’d get your declared dependency, as well as any transitive dependencies with scope == runtime or scope == compile.
In Gradle 5.x, your compileClasspath will contain moduleX.jar and slf4j-api.jar BUT NOT slf4j-log4j12.jar. This is because the last one is declared in a POM with scope == runtime, and Gradle will no longer include that when compiling.
So if your code is referencing types from slf4j-log4j12.jar, then it will compile successfully with Gradle 4.x, but will fail to compile with Gradle 5.x.
Without knowing how you’re publishing, it’s difficult to provide help on this.
Can you describe what you have changed that has caused this change in the generated POM? Is this simply a factor of moving from Gradle 4.x to 5.x, or could it be due to some other change you made in the process?