maven supports parent-child relationship, where the configuration of the parent project is inherited by the child project. This relationship is specified using the <parent> element as below:
<parent> <groupId>com.mygroup</groupId> <artifactId>artifactId</artifactId> <version>1.1</version> </parent>
The pom file of the parent project will be first located in some place and then merged into the pom file of the child project. Usually the location of the parent pom file can be searched in the following three places in the preference order:
- relativePath
- local repository
- remote repository
The relative path, if not given explicitly, defaults to the pom file of the parent directory of the current project. If given explicitly, the relative path specifies the path of the parent pom file. This is usually the case, where the parent project is constructed by the project owner.
maven checks a) whether there is a pom file in the relativePath. b) whether that pom file contains the same coordinate as that in the <parent> element of the current project.
If the parent pom file couldn’t be found in the relativePath, maven will search it in the local repository using the coordinate of the parent project.
If the parent pom file couldn’t be found in the local repository, maven will further search it in the remote repository. If found, maven will download it, store it in the local repository and use its configuration in the child pom file.
Otherwise, maven will report an error.