Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven : Should I keep or remove declared dependencies that are also transitives dependencies?

Do you think it is a good practice to remove every transitive dependencies that can be found in a maven pom?

Example:
My project depends on A and B.
B is also a transitive dependency of A.
Should I keep B in my pom or remove it ?

What is the best:
having all known jars, even transitive one, declared on the pom or keeping only the top level jars ?

This is a little bit subjective, but I am trying to clean some huge poms (parent and children) with a lot of transitive dependencies. I want to keep my pom as simple as possible, but I want also them to be maintainable.

like image 359
Guillaume Avatar asked Nov 19 '10 15:11

Guillaume


People also ask

Should I include transitive dependencies?

Don't include transitive dependencies. Exception: if you are relying on it in your code (see Z in the graph above), you must declare it. See below for proper handling in these (rare) cases.

How does Maven resolve transitive dependencies?

Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.

Does Maven override dependency version?

By taking advantage of Maven's nearest definition logic, developers can override the version of a dependency by declaring it on the root pom. xml file.


1 Answers

If your project has direct dependencies on B then you should keep it even if B is a transitive dependency of A. It can be that in the next version A won't use B an you'll have to restructure the pom.xml.

Generally, Maven dependencies should reflect the logical project dependencies.

like image 169
lexicore Avatar answered Oct 11 '22 15:10

lexicore