fail gradle build if transitive dependency is used directly?

radai :

im looking for a way to fail my gradle build if my code directly uses (so imports) a transitive dependency.

what i mean is if my project has a (compile) dependency on module A, and module A depends on B (so B is in my transitive dependencies and available on my runtime classpath) and my code directly imports and uses classes from B, i want my build to fail.

here's a maven plugin that does what i want - https://github.com/Scout24/illegal-transitive-dependency-check - but i cant find a gradle one?

Ahmed A.Hamid :

I think the 2 plugins below may be what you're looking for.

  1. https://github.com/wfhartford/gradle-dependency-analyze

    From the README:

    This plugin attempts to replicate the functionality of the maven dependency plugin's analyze goals which fail the build if dependencies are declared but not used or used but not declared.

  2. https://github.com/nebula-plugins/gradle-lint-plugin

    On the Unused Dependency Rule wiki page:

    1. Promotes transitive dependencies that are used directly by your code to explicit first order dependencies

I have to say I haven't used either one myself, but they seem to address your concern.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=152289&siteId=1