2

I have project P. P depends on library L1, and L1 depends on library T1.

Now, an unsuspecting developer comes along and modifies the code of P to include references to T1. This works, since P has a transitive dependency on T1 in the build, therefore T1 is available in P.

However, I would like Gradle to show me a report or warning that T1 should really be added as a direct dependency of P in the build, otherwise the dependency graph isn't really correct: after our hapless developer added his code, P references classes in T1 but does not depend on it explicitly.

How can I do this?

Raman
  • 17,606
  • 5
  • 95
  • 112
  • Do you mean that no class of T1 is ever used directly by the code of P? If that's what you mean, I don't think gradle is able to tell you that a library doesn't need to be in its direct dependencies. If P does use classes of T1, then T1 should be in its dependencies. – JB Nizet May 12 '17 at 17:23
  • No I mean the opposite -- P *does* use classes of T1, but T1 is not in its dependencies directly. This works because T1 is in its transitive dependencies, but I'd like to know about it so that T1 can be added into its direct dependencies. – Raman May 12 '17 at 17:28
  • @Raman, at least you can [disable transitive dependencies](http://stackoverflow.com/questions/17815864/gradle-how-to-disable-all-transitive-dependencies), so that your build will simply fail if a class is used from a transitive dependency. – hotkey May 12 '17 at 18:19
  • 3
    @hotkey That's like using an 18-wheeler to move a laptop :-) I don't want to turn off transitive dependencies entirely -- that would be a nightmare. – Raman May 12 '17 at 18:24

1 Answers1

0

The Nebula Lint plugin https://github.com/nebula-plugins/gradle-lint-plugin is capble of identifying unused dependencies as well of direct use of transitive dependencies.

I found a howto article here: https://www.baeldung.com/gradle-finding-unused-dependencies

rainer198
  • 3,195
  • 2
  • 27
  • 42
  • Looks like it would solve the problem, except most of my projects can't use it: "Gradle Lint Plugin currently doesn't support kotlin build script" (https://github.com/nebula-plugins/gradle-lint-plugin/issues/166) – Raman Dec 01 '22 at 14:08