Gradle 7.0 removes the compile and runtime dependency configurations, requiring older Java build scripts to choose replacements. For a shared library, api makes a dependency available when another project compiles against the library, while implementation keeps it off that consumer’s compile classpath. Replacing every compile entry with api can therefore leave dependencies exposed to downstream builds even when those projects do not need them to compile. [S8][S9]
The upgrade guide shows one way the break appears: an error beginning “Could not find method testCompile()”. Gradle attributes that example to a removed dependency configuration, despite its resemblance to a compilation error. The replacement for testCompile is testImplementation. Other names have specific successors too: runtime becomes runtimeOnly, and testRuntime becomes testRuntimeOnly. The runtimeOnly configuration is for dependencies needed to run the software, not to compile it. The old compile declaration has no single replacement; the choice is api or implementation. [S8][S9]
For that choice, inspect the library’s interface rather than just its import statements. Gradle recommends implementation where possible. A type used only inside a method body or a private member belongs there; a dependency whose type appears in an exposed superclass, method parameter or field belongs in api. The Java Library plugin documentation illustrates the distinction with a public constructor parameter and a helper used only inside a method. The constructor’s caller needs the parameter type available to compile; the internal helper need not be added to the caller’s compile classpath. The api configuration requires the java-library plugin. [S8][S9]
Using implementation does not make the dependency unnecessary at runtime. Gradle’s configuration table explicitly says implementation dependencies are still exposed to consumers when the software runs. The narrower boundary is what those consumers receive for compilation. For a shared-library migration, a useful check is to compile a representative project that uses the library, not just the library itself. Gradle warns that consumers fail to compile when implementation types leak into the public interface. That failure can reveal a scope choice that needs correction; it is not a reason to label every dependency api. [S9]
Gradle’s migration sequence starts before the version switch. On the existing build, its documented console check is gradle help --warning-mode=all. The guide then calls for updating plugins, updating the wrapper and running the project to investigate errors. It warns that plugins can break because internal Gradle interfaces have changed or disappeared. Correcting dependency declarations does not establish that those plugins are compatible. [S8]
Source documents
- Gradle 7.0: upgrading from Gradle 6.x — release-tag sourcehttps://raw.githubusercontent.com/gradle/gradle/d5661e3f0e07a8caff705f1badf79fb5df8022c4/subprojects/docs/src/docs/userguide/migration/upgrading_version_6.adoc
- Gradle 7.0: Java Library Plugin — release-tag sourcehttps://raw.githubusercontent.com/gradle/gradle/d5661e3f0e07a8caff705f1badf79fb5df8022c4/subprojects/docs/src/docs/userguide/jvm/java_library_plugin.adoc
