6

When using Maven with Java, is it possible to see where a dependency is used? Specifically to know which classes in your project import a class from a given dependency?

This is especially difficult when the package naming of the class and the dependency declaration's tags do not line up.

For example, given a POM which contains a dependency:

<dependency>
  <groupId>org.company.project</groupId>
  <artifactId>someartifact</artifactId>
  <version>1.0</version>
</dependency>

find all classes that uses it (such as):

import org.company.similarprojectnamebutnotquitethesame.packagecontinued.SomeClass

TLDR: Is there an efficient way to locate all files in my project that use a given dependency?

JMess
  • 623
  • 9
  • 11
  • 1
    See here: http://search.maven.org/#advancedsearch%7Cgav and put your imported class into the field `classname`... – khmarbaise Nov 15 '17 at 08:39
  • @khmarbaise this is great; but are there maven plugins or something that can be exact? – JMess May 26 '20 at 20:46
  • If you want to know which of your own classes depend on this dependency, you can simply remove it from your classpath and see which class generate errors. – Conffusion Sep 01 '20 at 09:54

1 Answers1

1

Use a JAR search engine that matches the class name with a package, such as findjar.com or help4j.com

Piotr Wilkin
  • 3,446
  • 10
  • 18
  • There can be thousands of classes contained within a dependency. You'd need to search your project for every single one. Inversely, you could do a search for every single import in your project. Either way is painful. – JMess Nov 14 '17 at 19:45