Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding eclipse maven dependency hierarchy

I want to understand the dependencies for a multi-module maven project and for that referred to eclipse dependency hierarchy.

I did understand fairly, however some of the things I am not able to understand at all.

Below is the screen shot.

The things which I didn't understand are:

--> managed from 1.0.2 [Compile}

--> managed from 1.0.2 (omitted for conflict with 1.0.0) [Compile]

I did search online but I got information in traces. Can anyone help me understand what they mean in easy to understand?

Thanks.

enter image description here

like image 899
CuriousMind Avatar asked Aug 28 '18 13:08

CuriousMind


People also ask

How does Eclipse determine dependency hierarchy?

Maven Dependency Tree in Eclipse IDEEclipse pom. xml “Dependency Hierarchy” tab shows the dependency tree of the project. It has two sides - the left side shows verbose output and the right side shows the resolved dependencies. We can use the “Filter” option to look for a specific dependency.

How do you analyze a dependency tree in Maven?

A project's dependency tree can be filtered to locate specific dependencies. For example, to find out why Velocity is being used by the Maven Dependency Plugin, we can execute the following in the project's directory: mvn dependency:tree -Dincludes=velocity:velocity.

What is Maven dependencies in Eclipse?

It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Now, you can add a dependency in pom.xml.

How do dependencies work in Maven?

Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk.


1 Answers

Maven builds a flat classpath from the dependency tree each for compiling ([compile]), for testing, and for running.

In a flat classpath, unlike OSGi, a dependency can only exist in one version. In your cropped screenshot, there is on the second level among other things:

  • kafka-streams 1.0.2 and
  • kafka-clients 1.0.0.

kafka-streams 1.0.2 requires kafka-clients 1.0.2 which conflicts to kafka-clients 1.0.0. Therefore kafka-streams 1.0.2 is omitted for conflicts with 1.0.0 even if the version 1.0.2 is required here ("managed from 1.0.2").

More detailed:
The classpath which is used to compile or run a plain Java application is flat: all required libraries are globally specified as an ordered list. It is not possible to use a library of a specific version for one package and for another package the same library in a different version.
In Maven dependencies builds a tree: each dependency might have its own dependencies. Maven maps the tree of dependencies to the classpath, an ordered list of libraries. If in the Maven dependencies tree the same library exists in different versions, it is not possible to create a flat classpath. This is a conflict.
This conflict is resolved by picking one version and omitting all other versions. At the place where the picked version is used instead of the required version, (managed from <required but not picked version>) and (omitted for conflict with <picked version to use instead>) is displayed.
In addition, Maven can create different classpaths to compile, to test or to run a Java application via so-called scopes. The [compile] scope is the default scope for using a library in all tasks: compiling, testing and running.

Make sure that the versions specified in the pom.xml file are compatible with each other (which is not yet the case in your screenshot): you have to upgrade kafka-clients from 1.0.0 to 1.0.2 (or downgrade the other libraries).

like image 191
howlger Avatar answered Sep 25 '22 03:09

howlger