Maven Dependency Convergence Error on Direct Dependency - maven

i've encountered a weird dependency convergency error while maven-enforcer-plugin is complaining about dependency convergency error on my direct dependency.
For example:
A -- B:1.0
|
-- C:1.0
|
-- B:1.1
A is my project and i specify B:1.0 as A's direct dependency in A's pom file. However, A also depends on C:1.0, which has a transitive dependency on B:1.1. Now maven is complaining about convergency error on B:1.0 and B:1.1.
In my understanding, once i specified a direct dependency in the master pom, we will stick to the version all the way for our project?
In this example, it should be B:1.0 that will be used by the project.
Am i understanding it incorrectly?
Thanks

To resolve convergence Errors, put the chosen dependency version into <dependencyManagement>.
A direct dependency will not resolve this kind of error.

Related

how to find usage of a dependency in a pom

I am working on a maven project, there is a dependency in the pom added, but I don't know where it is used in the code, so if it is not used I want to delete it.
so how can I tell where this dependency is used?
note that the dependency I am mentioning is under
its name is maven-assembly-plugin

I have big project in IntelliJ IDEA(UE) and list of External Libraries. How can I find where in the project I add this lib from the maven?

I have jackson-core-2.9.0 in the list of External Libraries, but I cant find where I added this lib in the project
You must understand how maven dependency works.
If you add any dependency to your pom.xml which is direct dependency to your project.
Then those direct dependencies have direct dependencies of their own and those dependencies have direct dependencies of their own and so on until there are no direct dependencies, these are called transitive dependencies of your project.
Use mvn dependency:tree to display all you your dependencies in tree structure to find which direct dependency has jackson-core-2.9.0 as dependency.
Note: more than one direct dependency can have jackson-core-2.9.0(or any other dependency) as dependency

writing pom.xml for maven dependencies sharing same dependency

I am creating my custom-exception dependency which uses org.springframework.web as its dependency.
so I will be using custom-exception as dependency in a master-project which also has org.springframework.web as one of its dependency.
so my concern is how do i write pom.xml file for custom-exception so that I can include it in master-project without getting any conflicts.
Any extra information regarding dependency versioning and scope will be appreciated.
This is the first time I am creating maven dependency

Maven transitive dependency not found. Leads to build error

I'm trying to build a Java project with Maven. My pom.xml includes mainly dependencies, some of which have their own transitive depedencies.
When I run 'mvn compile' most dependencies are loaded fine, but some of the transitive ones are not found, giving the warning "[WARNING] The POM for artifact_name is missing, no dependency information available". This leads to the Maven compile to fail.
The logs show, that the dependencies have been searched from Maven and Jboss public repositories.
What can I do in this situation, when a transitive dependency is not found?
How can I determine what dependency requires this transitive dependency? Command 'mvn dependency:tree' does not work, as it ends in build failure
Thanks in advance!
EDIT: I decided to delete all changes made to the pom.xml and downloaded the original one. After that the warnings with the transitive dependencies went away. So it seems that the issue was possibly with the syntax or some other change in the pom.xml.
I decided to delete all changes made to the pom.xml and downloaded the original one from our repository. After that the warnings with the transitive dependencies went away. So it seems that the issue was probably with the syntax or some other change in the pom.xml

How can I expect maven to resolve dependencies required by the child jar?

I have a parent project(has its own pom.xml) in which I import the child project as a jar with its own pom.xml.
In the parent pom.xml I have specified my child jar as a dependency - this gets resolved, but i want maven to resolve the dependencies required by my child jar.
My Use case to replicate :
When I include spring-web-mvc.jar the transitive dependencies are resolved automatically.
I have a similar requirement where I include my child.jar into a main framework project and expect the transitive dependencies to get resolved (Notw: the child.jar is not hosted it is packaged as jar and present on the local file system)
Current Structure:
Child Project:
|----/src/main/java
|----/src/main/resources
|----child-pom.xml
>This child project will be a jar as dependency in the parent project
Parent Project
|----/src/main/java
|----/src/main/resources
|----/src/main/webapp/WEB-INF/lib/child.jar
|---- parent-pom.xml
The problem:
When i create a war from parent project i want all the dependecy including transitive ones to show in WEB-INF lib.
Currently this is not happening.
First when talking of parent/ child Maven projects normaly you have your"childs" specified as modules in a common parent project which itself is beeing packed with the packaging type pom rather than make them a dependency of the parent project.
When it comes to the dependencies of your "childs" or generally "dependencies of your dependencies" those are called transitive dependencies and are pretty well explained in the official documentation found here: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
The resolving of those transitive dependencies is one of Mavens core strenghts and guaranteed by default unless they lead to conflicts that make the build fail.
Two things to help here are having a closer look into the enforcer plugin (http://maven.apache.org/enforcer/maven-enforcer-plugin/) and the shader plugin (http://maven.apache.org/plugins/maven-shade-plugin/) .... well and the official documentation of corse (reading the whole thing takes less than a day - then supports you further for specific topics whereas we gladly further support you too if you already have pom.xml files and you are stuck somewhere.
While the enforcer-plugin covers certain conflicts regarding different versions of the same artefacts the shader plugin will just pack everything you specified to a single jar for reverseengineering (its not the normal use case but i sometimes use it that way if i am not absolutly sure what ends in my final archives).
Also worth a look at is the dependency-plugin already available in the maven distributions - mvn dependency:tree -Dverbose will give you pretty detailed information on the resolved dependencies (and probably version conflicts).

Resources