Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

Generic Top

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:


1. Overview

When using Maven to manage our project dependencies, we can lose track of what dependencies are used in our application.

In this short tutorial, we'll cover how to use the Maven dependency plugin, a plugin that helps us find unused dependencies in our project.

2. Project Setup

Let's begin by adding a couple of dependencies, slf4j-api (the one we will be using) and common-collections (the one we won't use):


We can access the Maven dependency plugin without specifying it in our pom. In any case, we can use the pom.xml definition to specify the version and also some properties if needed:


3. Code Sample

Now that we have our project set up, let's write a line of code where we use one of the dependencies we defined before:

public Logger getLogger() {
    return LoggerFactory.getLogger(UnusedDependenciesExample.class);

The LoggerFactory from the Slf4J library is returned in a method, but there's no use of the common-collections library, making it a candidate for removal.

4. Find Unused Dependencies

Using the Maven dependency plugin, we can find the dependencies that are not in use in our project. For that, we invoke the analyze goal of the plugin:

$ mvn dependency:analyze

[INFO] --- maven-dependency-plugin:3.1.1:analyze (default-cli) @ maven-unused-dependencies ---
[WARNING] Unused declared dependencies found:
[WARNING]    commons-collections:commons-collections:jar:3.2.2:compile
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.225 s
[INFO] Finished at: 2020-04-01T16:10:25-04:00
[INFO] ------------------------------------------------------------------------

For every dependency that is not in use in our project, Maven issues a warning in the analysis report.

5. Specify Dependencies as Used

Depending on the nature of the project, sometimes we might need to load classes at runtime, like for example in a plugin oriented project.

Since the dependencies are not used at compile-time, the maven-dependency-plugin would issue a warning stating that a dependency is not being used, when in fact it is. For that, we can enforce and instruct the plugin that a library is being used.

We do this by listing the dependencies inside the usedDependencies property:


Running the analyze goal again, we see that the unused dependency is no longer considered in the report.

6. Conclusion

In this short tutorial, we learned how to find unused maven dependencies. It's a good practice to check for unused dependencies regularly since it improves maintainability and reduces the library size of our project.

As always, the full source code with all examples is available over on GitHub.

Generic bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

Maven footer banner
Inline Feedbacks
View all comments
Comments are closed on this article!