Detecting unused/undeclared dependencies

As your project becomes large and the number of dependencies increase (including transitive dependencies), it is good to know if we have ended up declaring dependencies that we are not using, or if we are using undeclared dependencies (which are brought in by transitive dependencies).

How to do it...

Use the following steps to detect the unused/undeclared dependencies:

  1. Run the following Maven command on the demo-selendroid project that we used earlier:
    mvn dependency:analyze
    
  2. Note the report generated:
    [WARNING] Used undeclared dependencies found:
    [WARNING]    org.seleniumhq.selenium:selenium-api:jar:2.43.1:compile
    [WARNING]    org.hamcrest:hamcrest-library:jar:1.3:compile
    [WARNING] io.selendroid:selendroid-common:jar:0.12.0:compile ...

Get Apache Maven Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.