Search code examples
eclipsemavenpom.xmlmaven-dependency

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


Solution

  • 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).