Maven pom.xml文件解读

实习一年过去,转正也半年,总觉得自己缺少点什么,后来用多方面感受到自己的基础底蕴还不足,研究东西,不要太浅显,深一点。不要觉得自己研究的东西low,研究深了,一通百通。先了解一波maven pom.xml文件配置各节点意思,再慢慢深究。

<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>
 
 
  <!-- The Basics 基础部分-->
  <!-- groupId 在一个项目中通常是唯一的,手动定义,爱叫啥就叫啥 -->
  <groupId>...</groupId>
  <!-- artifactId 项目的通用唯一标识符,一般由项目模块的包名定义与其他项目或者模块分开 示例:org.apache.maven -->
  <artifactId>...</artifactId>
  <!-- version 此项目本模板的当前当前版本 -->
  <version>...</version>
  <!-- packaging 此项目打包方式,有:pom,jar,maven-plugin,ejb,war,ear,rar 详细参考:http://maven.apache.org/ref/current/maven-core/default-bindings.html -->
  <packaging>...</packaging>
  <!-- dependencies pom依赖的父级,下一级是各个需要的依赖,此元素描述与项目关联的所有依赖项 -->
  <dependencies>
    <!-- dependency pom依赖,maven会去下载这个依赖以及这个依赖需要的其他依赖 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <!-- type 需要的依赖包的类型 默认为jar -->
      <type>jar</type>
      <!-- scope 使用该包的范围,默认为compile -->
      <scope>test</scope>
      <!-- optional. Indicates the dependency is optional for use of this library. While the version of the dependency will be taken into account for dependency calculation if the library is used elsewhere, it will not be passed on transitively -->
      <optional>true</optional>
      <!-- exclusions 排除这个包依赖的其他包 -->
      <exclusions>
        <exclusion>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
  <!-- parent pom的父级,maven会先查找这个pom文件的父级的pom文件,然后再查找本级 -->
  <parent>...</parent>
  <!-- dependencyManagement 只是对内部依赖版本号进行管理,不会实际引入依赖 -->
  <dependencyManagement>...</dependencyManagement>
  <!-- modules 本项目本模块引入的其他模块,列出的每个模块都是包含该模块的目录的相对路径 -->
  <modules>...</modules>
  <!-- properties可以在整个POM中用作替换的属性 -->
  <properties>...</properties>
 
  <!-- Build Settings -->
  <!-- build 内部是构建项目需要的信息 -->
  <build>
    <!-- defaultGoal 项目构建没有指定目标时的默认构建方式 -->
    <defaultGoal>install</defaultGoal>
    <!-- directory 构建文件放置的目录 -->
    <directory>${basedir}/target</directory>
    <!-- finalName 调用生成的文件名 默认是${artifactId}-${version} -->
    <finalName>${artifactId}-${version}</finalName>
    <!-- filters 使用过滤时过滤的文件列表 -->
    <filters>
        <filter>filters/filter1.properties</filter>
    </filters>
    <!-- resources. This element describes all of the classpath resources such as properties files associated with a project. These resources are often included in the final package 就是build时引入的资源文件-->
    <resources>
      <resource>
        <!-- targetPath指定用于放置构建中的资源集的目录结构 -->
        <targetPath>META-INF/plexus</targetPath>
        <!-- filtering表示是否要为此资源启用过滤 -->
        <filtering>false</filtering>
        <!-- directory 此元素定义资源的位置 -->
        <directory>${basedir}/src/main/plexus</directory>
        <!-- includes 指定要包含在该指定目录下的资源的文件 -->
        <includes>
          <include>configuration.xml</include>
        </includes>
        <!-- excludes 指定排除在该指定目录下的资源的文件 -->
        <excludes>
          <exclude>**/*.properties</exclude>
        </excludes>
      </resource>
    </resources>
    <!-- 此元素描述所有路径资源与项目测试关联的属性文件 -->
    <testResources>
      ...
    </testResources>
    <!--plugins 除了groupId:artifactId:version的标准坐标之外,还有一些元素可以配置插件或者与之构建交互 -->
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <!-- extensions 是否加载此插件的扩展名。它默认为false -->
        <extensions>false</extensions>
        <!-- inherited 是否可继承本插件的包 -->
        <inherited>true</inherited>
        <!-- configuration 描述插件的配置,和插件自身属性有关的配置 -->
        <configuration>
          <classifier>test</classifier>
        </configuration>
        <!-- dependencies 此项目需要引入到插件的其他依赖项 -->
        <dependencies>...</dependencies>
        <!-- executions 在构建生命周期中要执行的一组目标的多个操作 -->
        <executions>
            <execution>
            <!-- 此执行的标识符,用于在构建期间标记目标,并用于匹配继承期间要合并的执行 -->
                <id>echodir</id>
                <!-- goals 使用给定配置执行的目标 -->
                <goals>
                  <goal>run</goal>
                </goals>
               <!-- phase 将此执行中的目标绑定到的构建生命周期阶段。如果省略,目标将绑定到元数据中指定的默认值。 --> <phase>verify</phase>
               <!-- inherited 是否应将任何配置传播到子POM --> <inherited>false</inherited>
               <!-- 与上面相同,但是将配置限制在这个特定的目标列表中,而不是插件下的所有目标 -->
                <configuration>
                  ...
              </configuration>
            </execution>
        </executions>
        <!-- 用于管理一组POM中使用的默认插件信息的部分。 -->
        <pluginManagement>
          <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                       <id>pre-process-classes</id>
                       <phase>compile</phase>
                       <goals>
                          <goal>jar</goal>
                      </goals>
                      <configuration>
                         <classifier>pre-process</classifier>
                      </configuration>
                    </execution>
                </executions>
            </plugin>
          </plugins>
        </pluginManagement>
      </plugin>
    </plugins>
  </build>
  <!-- 此元素包括用于在Maven生成的站点上生成报告的报告插件的规范 -->
  <reporting>
    <!-- outputDirectory 在何处存储所有生成的报告 -->
    <outputDirectory>${basedir}/target/site</outputDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.0.1</version>
        <!-- 一组报告的多个规范 -->
        <reportSets>
          <reportSet></reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>
  
 
  <!-- More Project Information -->
  <!-- 项目全称 -->
  <name>...</name>
  <!-- 项目描述 -->
  <description>...</description>
  <!-- 项目主页的URL -->
  <url>...</url>
  <!-- 项目开始的年份,用4位数字指定。此值用于生成版权通知以及作为信息 -->
  <inceptionYear>...</inceptionYear>
  <!-- 此项目的所有许可证 -->
  <licenses>
      <license>
        <name>Apache License, Version 2.0</name>
        <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
        <comments>A business-friendly OSS license</comments>
      </license>
  </licenses>
  <!-- 项目所属组织的各种属性 -->
  <organization>
    <name>Codehaus Mojo</name>
    <url>http://mojo.codehaus.org</url>
  </organization>
  <!-- 项目的提交者 -->
  <developers>
    <developer>
      <id>jdoe</id>
      <name>John Doe</name>
      <email>[email protected]</email>
      <url>http://www.example.com/jdoe</url>
      <organization>ACME</organization>
      <organizationUrl>http://www.example.com</organizationUrl>
      <roles>
        <role>architect</role>
        <role>developer</role>
      </roles>
      <timezone>America/New_York</timezone>
      <properties>
        <picUrl>http://www.example.com/jdoe/pic</picUrl>
      </properties>
    </developer>
  </developers>
  <!-- 尚未提交的项目的参与者 -->
  <contributors>
    <contributor>
      <name>Noelle</name>
      <email>[email protected]</email>
      <url>http://noellemarie.com</url>
      <organization>Noelle Marie</organization>
      <organizationUrl>http://noellemarie.com</organizationUrl>
      <roles>
        <role>tester</role>
      </roles>
      <timezone>America/Vancouver</timezone>
      <properties>
        <gtalk>[email protected]</gtalk>
      </properties>
    </contributor>
  </contributors>
  
 
  <!-- Environment Settings -->
  <!-- 有关用于管理此项目的问题跟踪(或错误跟踪)系统的信息,主要用于生成文档 -->
  <issueManagement>
    <!-- 问题管理系统的名称 -->
    <system>Bugzilla</system>
    <!-- 项目中使用问题管理的路径 -->
    <url>http://127.0.0.1/bugzilla/</url>
  </issueManagement>
  <!-- 持续集成管理 -->
  <ciManagement>
    <system>continuum</system>
    <url>http://127.0.0.1:8080/continuum</url>
    <!-- 用于在生成失败时通知开发人员/用户的配置,包括用户信息和通知模式 -->
    <notifiers>
      <notifier>
        <type>mail</type>
        <!-- 是否发送出错通知 -->
        <sendOnError>true</sendOnError>
        <!-- 失败时是否发送通知 -->
        <sendOnFailure>true</sendOnFailure>
        <!-- 成功时是否发送通知 -->
        <sendOnSuccess>false</sendOnSuccess>
        <!-- 警告时是否发送通知 -->
        <sendOnWarning>false</sendOnWarning>
        <!-- 此处显示特定于此通知程序的扩展配置 -->
        <configuration><address>[email protected]</address></configuration>
      </notifier>
    </notifiers>
  </ciManagement>
  <!-- mailingLists 包含项目联系人邮件列表的信息 -->
  <mailingLists>
    <mailingList>
      <!-- 包含项目联系人姓名 -->
      <name>User List</name>
      <subscribe>[email protected]</subscribe>
      <unsubscribe>[email protected]</unsubscribe>
      <!-- 可接受邮件的邮箱 -->
      <post>[email protected]</post>
      <!-- 可以浏览邮件列表的URL -->
      <archive>http://127.0.0.1/user/</archive>
      <!-- 可以浏览邮件列表的备胎 -->
      <otherArchives>
        <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive>
      </otherArchives>
    </mailingList>
  </mailingLists>
  <!-- 本项目版本控制管理的信息 -->
  <scm>
    <!-- 本项目版本控制链接地址,比如https://github.com/Squidyu/Sentinel -->
    <connection>scm:svn:http://127.0.0.1/svn/my-project</connection>
    <!-- 和connection一样,对于开发者权限不只是只读权限,不需要pullrequest -->
    <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection>
    <!-- 当前代码的tag -->
    <tag>HEAD</tag>
    <!-- 可公开浏览的存储库。例如,通过ViewCVS.(没理解) -->
    <url>http://127.0.0.1/websvn/my-project</url>
  </scm>
  <!-- 描述此项目的生成环境中的先决条件 -->
  <prerequisites>
    <maven>2.0.6</maven>
  </prerequisites>
  <!-- 用于发现依赖项和扩展的远程存储库位置列表 -->
  <repositories>
    <repository>
      <!-- 如何处理从此存储库下载的发行版 -->
      <releases>
        <!-- 是否启用该存储库 -->
        <enabled>false</enabled>
        <!-- 下载更新库的频率 -->
        <updatePolicy>always</updatePolicy>
        <!-- 当Maven将文件部署到存储库时,它还会部署相应的校验和文件。您可以选择忽略,失败或警告缺少或不正确的校验 -->
        <checksumPolicy>warn</checksumPolicy>
      </releases>
      <!-- 如何处理从此存储库下载的快照版 -->
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
        <checksumPolicy>fail</checksumPolicy>
      </snapshots>
      <id>codehausSnapshots</id>
      <name>Codehaus Snapshots</name>
      <url>http://snapshots.maven.codehaus.org/maven2</url>
      <!-- Maven 2引入的布局是Maven 2和3使用的存储库的默认布局。但是,Maven 1.x有不同的布局。使用此元素指定默认或遗留的元素 -->
      <layout>default</layout>
    </repository>
  </repositories>
  <!-- 用于发现构建和报告插件的远程存储库列表 -->
  <pluginRepositories>...</pluginRepositories>
  <!-- 项目的分发信息,该项目支持将站点和工件分别部署到远程Web服务器和存储库 -->
  <distributionManagement>
    <!-- 该项目的其他下载url -->
    <downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl>
    <!-- Maven在将项目传输到存储库时设置项目的状态 -->
    <status>deployed</status>
    <!-- 当存储库元素在POM中指定Maven可以下载远程工件以供当前项目使用的位置和方式时,distributionManagement指定此项目在部署时将在何处(以及如何)到达远程存储库。如果未定义snapshotRepository,则存储库元素将用于快照分发 -->
    <repository>
      <uniqueVersion>false</uniqueVersion>
      <id>corp1</id>
      <name>Corporate Repository</name>
      <url>scp://repo/maven2</url>
      <layout>default</layout>
    </repository>
    <snapshotRepository>
      <uniqueVersion>true</uniqueVersion>
      <id>propSnap</id>
      <name>Propellors Snapshots</name>
      <url>sftp://propellers.net/maven</url>
      <layout>legacy</layout>
    </snapshotRepository>
    <!-- 以上分配到存储库,distributionManagement负责定义如何部署该项目的网站和文档 -->
    <site>
      <id>mojo.website</id>
      <name>Mojo Website</name>
      <url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url>
    </site>
    <!-- 项目迁移 -->
    <relocation>
      <groupId>org.apache</groupId>
      <artifactId>my-project</artifactId>
      <version>1.0</version>
      <message>We have moved the Project under Apache</message>
    </relocation>
  </distributionManagement>
  <!-- 项目本地生成配置文件的列表,激活后将修改生成过程,要查看将在特定版本中激活的配置文件,请使用 maven-help-plugin命令查看 -->
  <profiles>
    <profile>
      <id>test</id>
      <!-- 自动触发包含此配置文件的条件 -->
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>sparrow-type</name>
          <value>African</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>
      <build>...</build>
      <modules>...</modules>
      <repositories>...</repositories>
      <pluginRepositories>...</pluginRepositories>
      <dependencies>...</dependencies>
      <reporting>...</reporting>
      <dependencyManagement>...</dependencyManagement>
      <distributionManagement>...</distributionManagement>
    </profile>
  </profiles>
</project>

猜你喜欢

转载自blog.csdn.net/qq_26400953/article/details/86568316