The relationship between the sub-project and the parent project in the POM file (the most complete)

1. pom file

        The pom file defines the maven configuration of a maven project. Generally, the pom file is placed in the root directory of the project or module. Maven follows convention over configuration.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>
project The root element of the entire pom configuration file, all configurations are written in the project element
groupId The ID of the project group , which is usually unique within an organization or project
artifactId The project 's identifier, usually the name of the project. It is unique under a project group
version The version number of the project , used to distinguish different versions of the same artifact
packaging This is the component type generated by the project , that is, the suffix name of the output file packaged by the project through maven, including jar, war, ear, pom, etc.

2. Parent pom and child pom relationship (inheritance)

  ①If the parent pom is

  <dependencies>

  </dependencies>

        Then the child pom will automatically inherit the dependencies of the parent pom, and there is no need for the child pom to import

  ②If the parent pom is

<dependencyManagement>
    <dependencies>

    </dependencies>
</dependencyManagement>

        Then the child pom will not automatically inherit the dependencies of the parent pom, unless it is declared in the child pom , the statement requires groupId and artifactId, and no version is required. This method is used to constrain the sub-pom. If you want to use it, you need to declare it.

3. Parent POM and child POM

(1) The role of the parent POM: to eliminate duplication of configuration .

(2) Child POM:

        Unconditionally inherit the dependencies element of the parent POM.

        ②The dependencies element of the child POM can selectively inherit the dependency management element of the parent POM

        ③The child pom can also specify the dependent version by itself, instead of using the parent pom.

        The child POM unconditionally inherits the plugins element of the parent POM ; the plugins element of the child POM can selectively inherit the pluginManagement element of the parent POM .
 

    <parent>
        <artifactId></artifactId>
        <groupId></groupId>
        <version></version>
    </parent>
parent Used to specify the parent project
groupId The child element of parent, the groupId of the parent project, used to locate the parent project
artifactId The child element of parent, the artifactId of the parent project, used to locate the parent project
version The child element of parent, the version of the parent project, used to locate the parent project
relativePath The child element of parent, used to locate the location of the parent project pom file

        Maven uses effective pom (parent project pom plus project's own configuration) to execute related goals, which helps developers to do as little configuration as possible in pom.xml. Of course, these configurations can also be overridden.

        The parent element can specify the parent pom. Users can customize a parent pom by adding the parent element , thereby inheriting the configuration of the pom. The parent element contains some sub-elements to locate the parent project and the pom file location of the parent project.

Guess you like

Origin blog.csdn.net/y1120944224/article/details/127919735