Post

What's the difference between implementation, api and compile in Gradle?

Gradle

What’s the difference between implementation, api and compile (compileOnly, runtimeOnly, testImplementation, testCompileOnly, testRuntimeOnly) in Gradle?

NameRoleConsumable?Resolveable?Description
apiDeclaring
API
dependencies
nonoThis is where you should declare
dependencies which are transitively
exported to consumers, for compile.
implementationDeclaring
implementation
dependencies
nonoThis is where you should
declare dependencies which are
purely internal and not
meant to be exposed to consumers.
compileOnlyDeclaring
compileOnly
dependencies
yesyesThis is where you should
declare dependencies
which are only required
at compile time, but should
not leak into the runtime.
This typically includes dependencies
which are shaded when found at runtime.
runtimeOnlyDeclaring
runtime
dependencies
nonoThis is where you should
declare dependencies which
are only required at runtime,
and not at compile time.
testImplementationTest
dependencies
nonoThis is where you
should declare dependencies
which are used to compile tests.
testCompileOnlyDeclaring test
compile only
dependencies
yesyesThis is where you should
declare dependencies
which are only required
at test compile time,
but should not leak into the runtime.
This typically includes dependencies
which are shaded when found at runtime.
testRuntimeOnlyDeclaring test
runtime dependencies
nonoThis is where you should
declare dependencies which
are only required at test
runtime, and not at test compile time.

References

This post is licensed under CC BY 4.0 by the author.