Technology Sharing

Introduction to important tags in pom.xml

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

In a Maven project,pom.xml The file is the configuration file of the Project Object Model (POM), which defines the project's dependencies, plugins, build configuration, etc. The following ispom.xml Some important tags in the file and their functions:

  1. <modelVersion>

    • Defines the version of the POM model. The currently commonly used versions are 4.0.0
    <modelVersion>4.0.0</modelVersion>
    
    • 1
  2. <groupId>

    • Defines the group ID of the project, usually representing an organization or company.
    <groupId>com.example</groupId>
    
    • 1
  3. <artifactId>

    • Defines the artifact ID of the project, which is the name of the project.
    <artifactId>my-project</artifactId>
    
    • 1
  4. <version>

    • Defines the version number of the project.
    <version>1.0.0</version>
    
    • 1
  5. <packaging>

    • Define how the project is packaged, such as jarwarpom etc. The default isjar
    <packaging>jar</packaging>
    
    • 1
  6. <name>

    • The name of the project.
    <name>My Project</name>
    
    • 1
  7. <description>

    • Description of the project.
    <description>This is a sample project</description>
    
    • 1
  8. <url>

    • The URL of the project's home page.
    <url>http://www.example.com</url>
    
    • 1
  9. <dependencies>

    • Defines the dependencies of the project. Each dependency is represented by <dependency> Label package.
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>5.3.8</version>
        </dependency>
    </dependencies>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
  10. <dependencyManagement>

    • Used to centrally manage the versions of project dependencies. Submodules can inherit these dependencies without specifying versions.
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>5.3.8</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  11. <repositories>

    • Defines the remote repository that the project depends on.
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  12. <build>

    • Contains build-related configurations, such as plugin configuration, resource configuration, etc.
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
  13. <properties>

    • Defines variables in a Maven build.
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    • 1
    • 2
    • 3
    • 4
  14. <profiles>

    • Define different build configurations that can be used in different environments.
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <env>development</env>
            </properties>
        </profile>
    </profiles>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

These tags constitute pom.xml The basic framework for configuring and managing Maven projects. Each tag has a specific role and helps developers define various aspects of the project.