maven的pom文件有各种标签,有的比较常用,需要掌握,有的很少遇到,则不一定需要掌握。

所以找了个规模较大的开源项目来分析一下有哪些标签比较常用,以及他们的具体含义。

加上了个人的注释后:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2018-2020 Pnoker. All Rights Reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<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">

<!--    maven模块的版本名-->
    <modelVersion>4.0.0</modelVersion>
<!--    组织id-->
    <groupId>com.dc3</groupId>
<!--    项目名-->
    <artifactId>iot-dc3</artifactId>
<!--    版本号-->
    <version>1.1.0</version>
<!--    打包方式pom、jar、war
pom是给父项目用的,父项目用作项目的整合,maven install后,不会生成jar包或者war包
jar是默认的打包方式
war web应用打包方式。不过现在springboot一般情况下也打成jar包
-->
    <packaging>pom</packaging>
<!-- 项目名称,maven生成文档用到,只起到说明的作用-->
    <name>${project.artifactId}</name>
<!--    同上-->
    <url>https://github.com/pnoker/iot-dc3</url>
<!--    同上,成立年份-->
    <inceptionYear>2017-2020</inceptionYear>
<!--    描述-->
    <description>
        IOT-DC3 可分布式的物联网(IOT)平台 , 基于开源Spring Cloud框架搭建,实现设备互联、管理、数据采集、代码生成、快速开发和可视化等,
        兼容多种流行的物联网数据接入协议(Mqtt\Socket\Modbus-Tcp\Rtsp\Rtmp\Siemens PLC S7\OpcUa\OpcDa...),是一整套完整的物联系统解决方案。
    </description>

<!--    有哪些子模块-->
    <modules>
        <module>dc3-gateway</module>
        <module>dc3-center</module>

        <module>dc3-transfer</module>
        <module>dc3-driver</module>

        <module>dc3-api</module>
        <module>dc3-common</module>
    </modules>

<!--    参数的具体值-->
    <properties>
        <caffeine.version>2.8.4</caffeine.version>
        <mybatis.plus.version>3.3.2</mybatis.plus.version>

        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <spring-platform.version>Cairo-SR8</spring-platform.version>
        <spring-boot-admin.version>2.2.4</spring-boot-admin.version>

        <java.version>1.8</java.version>
        <codecov.version>2.7</codecov.version>
        <findbugs.version>3.0.5</findbugs.version>
        <maven.jar.plugin>3.2.0</maven.jar.plugin>
        <maven.resource.plugin>3.1.0</maven.resource.plugin>
        <maven.dependency.plugin>3.1.1</maven.dependency.plugin>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

<!--    实际导入的依赖,子模块将会继承这些项目
-->
    <dependencies>

        <!-- Spring Configuration-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
<!--
表示依赖关系对于使用此库是可选的。如果在其他地方使用该库,则在计算依赖关系时会考虑依赖关系的版本,但不会传递传递。
-->
            <optional>true</optional>
        </dependency>

        <!-- Spring Aop -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
        </dependency>

        <!-- Eureka -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>

        <!-- Hystrix -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        


        <!-- Actuator -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- Admin -->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
        </dependency>

        <!-- Caffeine Cache -->
        <dependency>
            <groupId>com.github.ben-manes.caffeine</groupId>
            <artifactId>caffeine</artifactId>
            <version>${caffeine.version}</version>
        </dependency>

        <!-- Apache Pool2 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
<!--            scope表示一个以来的作用范围,通常有一下几个取值

compile:默认值, 表示参与项目构建的一切流程
test: 仅仅测试阶段用到,项目打包的时候不会打包进去
runtime: 与compile相比,不参与编译,其他过程例如运行、测试等都参与。
provided: 但是打包的时候不包括他,其他所有流程都参与(太惨了)

system:  和 systemPath一起用,从本地加载依赖。 作用范围和provided一样

-->
            <scope>test</scope>

<!--            exclusions 把不需要的部分排除在外
                比如springboot不需要内置的tomcat时,就可以用这个排除
-->
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

<!--    依赖管理
      区别于上面的dependencies,
      dependencyManagement只是“定义依赖”,并没有实际引入。
      他的作用是提前定义版本号,子模块需要引入jar包时,就不需要再加版本了。
-->
    <dependencyManagement>
        <dependencies>

            <!-- Spring Cloud 依赖 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>io.spring.platform</groupId>
                <artifactId>platform-bom</artifactId>
                <version>${spring-platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Spring Boot Admin -->
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-server</artifactId>
                <version>${spring-boot-admin.version}</version>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-starter-client</artifactId>
                <version>${spring-boot-admin.version}</version>
            </dependency>

            <!-- Mybatis Plus -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-extension</artifactId>
                <version>${mybatis.plus.version}</version>
            </dependency>

            <!-- dc3 Api -->
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-api-auth</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-api-manager</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-api-data</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-api-rtmp</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>

            <!-- dc3 Driver  -->
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-sdk</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>

            <!-- dc3 Common -->
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-core</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-config</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.dc3</groupId>
                <artifactId>dc3-base</artifactId>
                <version>${project.version}</version>
                <scope>compile</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

<!--    插件-->
    <build>
        <finalName>${project.name}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
<!--                    有的插件需要一些参数,可以在这里配置-->
                    <configuration>
                        <target>${maven.compiler.target}</target>
                        <source>${maven.compiler.source}</source>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven.jar.plugin}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                    <configuration>
                        <finalName>${project.build.finalName}</finalName>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <!-- 过滤文件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven.resource.plugin}</version>
                    <configuration>
                        <nonFilteredFileExtensions>
                            <nonFilteredFileExtension>ico</nonFilteredFileExtension>
                        </nonFilteredFileExtensions>
                    </configuration>
                </plugin>
                <!-- 代码覆盖检测 -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>cobertura-maven-plugin</artifactId>
                    <version>${codecov.version}</version>
                    <configuration>
                        <formats>
                            <format>html</format>
                            <format>xml</format>
                        </formats>
                    </configuration>
                </plugin>
                <!-- jar依赖包打包配置 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>${maven.dependency.plugin}</version>
<!--                    executions设置插件的作用目标,
                        一个插件的作用目标可能不止一个
-->
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- FindBugs Plugin -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>${findbugs.version}</version>
                    <configuration>
                        <!-- 设置分析工作的等级,可以为Min、Default和Max -->
                        <effort>Low</effort>
                        <!-- Low、Medium和High (Low最严格) High只扫描严重错误。建议用Medium-->
                        <threshold>Low</threshold>
                        <failOnError>false</failOnError>
                        <includeTests>false</includeTests>
                    </configuration>
                    <executions>
                        <execution>
                            <id>run-findbugs</id>
                            <!-- 在package(也可设为compile) 阶段触发执行findbugs检查,比如执行 mvn clean package -->
                            <phase>package</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <developers>
        <developer>
            <id>pnoker</id>
            <name>pnoker</name>
            <email>pnokers@icloud.com</email>
            <organization>pnoker.github.io</organization>
        </developer>
    </developers>

<!--    项目使用的协议-->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

<!--   打包上传到私服或者github, 需要和配置文件中的server节点配合使用-->
    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub DC3 Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/pnoker/iot-dc3</url>
        </repository>
    </distributionManagement>

<!--    配置仓库地址-->
    <repositories>
        <repository>
            <id>aliyun</id>
            <name>aliyun</name>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
<!--            自动获取最新的快照
详情可以参考:   https://www.runoob.com/maven/maven-snapshots.html
-->
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

<!--   maven下载插件的地址
https://segmentfault.com/a/1190000020998920?utm_source=tag-newest
-->
    <pluginRepositories>
        <pluginRepository>
            <id>spring-plugin</id>
            <name>spring-plugin</name>
            <url>https://maven.aliyun.com/repository/spring-plugin</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

 

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐