Understanding eclipse maven dependency hierarchy
Asked Answered
I

1

13

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

Intercessory answered 28/8, 2018 at 13:10 Comment(0)
B
12

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

Bilharziasis answered 28/8, 2018 at 13:49 Comment(3)
Thanks for answering , very information, and I must say not easy to get this info "just googling". I have few more questions, please help me understand. 1) What is flat classpath? 2) Meaning of "managed from..." 3) "Omitted for conflict with...". I did google these messages, but I didn't get anything meaningful which could help me understand this. A request if you can elaborate a bit more to help understand a bit more. ThanksIntercessory
@Intercessory (1) Flat means in a classpath required libraries are globally specified as an ordered list whereas your screenshot shows the Maven dependencies as a tree (each dependency might have its own dependencies). You cannot say, for this package use a library 1.0.0 but for another package the same library 1.0.2 to compile it or to run it. Maven maps the tree of dependencies to the classpath (ordered list of libraries). (2+3) 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. ...Bilharziasis
@Intercessory ...(2+3) This conflict is resolved by picking one version and omitting all other versions. At the place where the selected version is used instead of the required version, (managed from <required but not used version>) and (omitted for conflict with <picked version to use instead>) is displayed.Bilharziasis

© 2022 - 2024 — McMap. All rights reserved.