Keeping an eye on transitive dependencies and tidying up the pom files time after time is a good practice.
A way of discovering transitive dependencies is to use the command "mvn dependency:analyse".
This command comes from a set of tools inside the maven-dependency-plugin.
In order to use it, you have to include the dependency plugin in your project like this:
<!- If you are just using it in a single module project-> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> </plugin> </plugins>
<!-- If you are using a multi module project then use this in the parent POM --> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> </plugin> </plugins> </pluginManagement>
This plugin can do multiple things, the analyze command is very useful for finding more information about dependencies.
Unused declared dependencies found: The dependencies are not used in the project
Used undeclared dependencies found: Transitive dependencies used in the project(not declared in the pom)
The output of the command will be presented as warning in the terminal, if you want to be very strict about keeping your your pom tidy,
you could add the analyze command in the build lifecycle and configure maven to fail the build if any warnings are found(Maybe I explain that in another
post sometime ;) ).
Another great tool that comes in the dependency plugin and that its worth mentioning, is
It will help you visualise the dependencies tree of your pom and understand it better.
Just some more interesting stuff about maven if you want to read more: