[Maven 基础课程]pom.xml

pom.xml 常见配置项

为了方便你入门,我总结了 pom.xml 中几个最常见、最重要的配置项,这些通常是你需要在项目中使用的。

项目坐标(GAV)

xml 复制代码
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

这部分定义了项目的唯一标识,是所有 Maven 项目的基石。

依赖管理(Dependencies)

xml 复制代码
<dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.32</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.9.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

: 包含所有项目依赖的列表。

: 定义一个具体的依赖。

scope: 定义依赖的范围。test 表示该依赖只在测试阶段有效,不会被打包到最终的 JAR 包中。关于 scope 更详细的知识可以参考:https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

我们找依赖一般去 maven 仓库找:https://mvnrepository.com/

属性(Properties)

xml 复制代码
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <slf4j.version>1.7.32</slf4j.version>
</properties>

这部分用于定义变量,方便统一管理版本号等配置,避免在多个地方重复硬编码。

构建配置(Build)

xml 复制代码
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
</build>

: 配置项目构建相关的设置。

: 配置项目使用的 Maven 插件。

: 定义一个具体的插件,例如 maven-compiler-plugin。

: 用于对插件进行详细配置,比如指定 Java 编译版本。

pom.xml 的更多信息可以参考:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html

相关推荐
arbalest10801 天前
xml文件学习
xml
开开心心_Every1 天前
定时管理进程:防止沉迷电脑的软件推荐
xml·java·运维·服务器·网络·数据库·excel
水哥ansys2 天前
ANSYS Workbench ACT二次开发XML语法介绍
xml·二次开发·水哥ansys
程序猿零零漆2 天前
Spring之旅 - 记录学习 Spring 框架的过程和经验(二)基于Xml方式Bean的配置
xml·spring
开开心心_Every3 天前
无广告干扰:简单好用文字LOGO设计工具
xml·java·网络·数据库·华为od·华为云·excel
武子康3 天前
Java-210 Spring AMQP 整合 RabbitMQ:JavaConfig 注解配置、RabbitTemplate 发送/同步接收与坑位速查
xml·java·spring·消息队列·rabbitmq·java-rabbitmq·mq
jiayong233 天前
`.flattened-pom.xml` 深度解析
xml
小李飞飞砖4 天前
RemoteViews的layout无法设置xml类型的Drawable,会报错
xml
武子康4 天前
Java-209 Spring AMQP 整合 RabbitMQ 实战:XML 配置直连交换机、RabbitAdmin 自动声明与收发闭环
xml·java·spring·rabbitmq·java-rabbitmq·java-activemq
利刃大大6 天前
【Mybatis】Mybatis入门 && 基础操作 && XML配置文件开发 && 多表查询 && 注入问题 && 数据库连接池
xml·数据库·mybatis