what does happen with maven dependencies

akhil chowdary :

suppose I have a project say A which is dependent on B. so when I build project A. does maven generates the artifact of A by bundling with project B artifact?

and suppose if project B is dependent on C. then when I build project A, will it by default takes the transitive dependency c to generate the artifact? and even if it takes, what will happen if I add C as a dependency in project A pom.xml? will maven takes the C artifact for two times to build A and generates a bigger artifact file?

Arvind Kumar Avinash :

what will happen if I add C as a dependency in project A pom.xml?

If C's dependency has already been resolved, maven will simply ignore it if it is declared elsewhere.

will maven takes the C artifact for two times to build A and generates a bigger artifact file?

No.

Please check https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies for more details.

Transitivity brings a very serious problem when different versions of the same artefacts are included by different dependencies. It may cause version mismatch issue in runtime. In this case, dependency:tree command is very useful in dealing with conflicts of JARs.

$ mvn dependency:tree

Check https://howtodoinjava.com/maven/maven-dependency-management/#dependency-tree for more details.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=418249&siteId=1