In AEM poms I have noticed that dependency name and versions are defined in the parent pom and child poms only have dependencies defined and it is not necessary to specify a version in child poms, as the version is managed at the Parent pom. So, I am not clear on following.
1. If we already have dependencies defined in the parent pom with version no, then why do we need to define the same dependency back in child pom.xml (core/pom.xml in case of AEM). Why can't maven look for dependencies in parent pom as it looks for version?
Solved! Go to Solution.
So this is a concept of dependency management in Maven multi-module project. In Dependency management, your parent pom defines dependencies and their versions then reference these dependencies in your submodules where needed. When you require other sub-modules in your project (ie. core) then the dependencies will be found transitively.
to maintain the versions, we specify the version in parent pom which is then inherited by child pom. if you change the version you will have to build the project keeping in the parent pom. if not changing then will refer the last build dependency version.
Maven – Introduction to the Dependency Mechanism
they have explained by example in the above link.
~ Prince
Views
Replies
Total Likes
please go with below article and you will understand the logic.
https://howtodoinjava.com/maven/maven-parent-child-pom-example/#parent-child
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
To match a parent POM, Maven uses two rules:
Reference from child POM file contains the same coordinates as stated in the parent POM file.
Child POM needs to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes.
This pom file will inherit all properties and dependencies from parent POM and additionally can include extra
sub-project specific dependencies as well.
Views
Replies
Total Likes
Hi Prince,
If I look at the example https://howtodoinjava.com/maven/maven-parent-child-pom-example/#parent-child , parent pom has two dependencies (junit and spring-core). And child pom has spring-security (assuming that it will inherit other two from parent). This makes sense to me because child pom is not defining the dependencies again.
But my question still remains - In AEM core/pom.xml, I still see the same dependency defined without version no. I mean, parent pom has same dependencies with version no and child pom has same without version no. Why are these duplicated? Why child pom is not inheriting dependencies from parent pom as mentioned in the above case?
So this is a concept of dependency management in Maven multi-module project. In Dependency management, your parent pom defines dependencies and their versions then reference these dependencies in your submodules where needed. When you require other sub-modules in your project (ie. core) then the dependencies will be found transitively.
to maintain the versions, we specify the version in parent pom which is then inherited by child pom. if you change the version you will have to build the project keeping in the parent pom. if not changing then will refer the last build dependency version.
Maven – Introduction to the Dependency Mechanism
they have explained by example in the above link.
~ Prince
Views
Replies
Total Likes
Great answer Prince!
Views
Likes
Replies