Is it possible to prevent code from importing pack...
# gradle
t
Is it possible to prevent code from importing packages from transitive dependencies pulled from maven central? I know you can do that from other gradle projects via 'implementation' and 'api' Something similar to Bazel's 'strict visibility'?
m
You mean to ignore transitive dependencies of a module that declared it as
api
but you want it to be
implementation
?
t
I think? If I have library
A
which lists a dependency on
B
where
B
is pulled from Maven Central (not inside my own project).
B
further depends on
C
which may or may not have been built with gradle or using proper module encapsulation. Currently
A
can import packages from
C
even though it only declared a dependency on
B
. I would like to prevent this situation where a library can depend on transitive dependencies.
m
I’ve asked that in Gradle Slack and there is no easy way to achieve that. I had the same issue with getting rid of implicit Dagger dependencies. What I did was to
exclude("C")
in
implementation("B") { … }
and then add it manually as
runtimeOnly("C")
to my project. So it’s still there at runtime but hidden from your code.
t
Thanks for the tip. I couldn’t find anything the Gradle docs so not surprising it’s actually not supported.