Maven 入門實戰(2)--POM

来源:https://www.cnblogs.com/wuyongyin/archive/2023/07/02/17392995.html
-Advertisement-
Play Games

POM( Project Object Model,項目對象模型 ) 是 Maven 工程的基本工作單元,它是一個 XML 文件,包含了項目的基本信息,用於描述項目如何構建,聲明項目依賴等等。執行任務或目標時,Maven 會在當前目錄中查找並讀取 POM,獲取所需的配置信息,然後執行目標。 1、基本 ...


POM( Project Object Model,項目對象模型 ) 是 Maven 工程的基本工作單元,它是一個 XML 文件,包含了項目的基本信息,用於描述項目如何構建,聲明項目依賴等等。執行任務或目標時,Maven 會在當前目錄中查找並讀取 POM,獲取所需的配置信息,然後執行目標。

1、基本配置

<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>

    <groupId>com.mycompany</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0.0</version>
    <description>項目描述</description>
    <name>項目名稱</name>
    <url>https://www.mycompany.com/myproject</url>
    <packaging>jar</packaging>
    <inceptionYear>2023</inceptionYear>
</project>

 配置說明:

節點 說明
project 工程的根標簽
modelVersion 模型版本,設置為:4.0.0;必需
groupId 工程組標識,它在一個組織或者項目中通常是唯一的;必需
artifactId 工程標識,它通常是工程的名稱;必需
version 工程版本號;必需
description 工程描述
name 工程名稱
url 工程主頁
packaging 打包類型,常見類型為:pom、jar、war、ear;預設為:jar
inceptionYear 項目創建年份,4 位數字;版權信息生成時需使用這個配置

2、parent

所有的 POM 都繼承自一個父 POM(無論是否顯式定義了這個父 POM),父 POM 包含了一些可以被繼承的預設設置。

<parent>
    <groupId>com.mycompany</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0</version>
    <relativePath/>
</parent>

配置說明:

節點 說明
groupId 父工程組標識;必需
artifactId 父工程標識;必需
version 父工程版本號;必需
relativePath 父工程 pom.xml 文件的相對路徑;預設值為:../pom.xml。Maven 首先在當前工程的目錄尋找父工程的 pom,其次在 relativePath,然後在本地倉庫,最後在遠程倉庫尋找父項目的 pom

3、prerequisites

prerequisites 元素用於描述構建該項目的先決條件。

<prerequisites>
    <maven>3.8.0</maven>
</prerequisites>

配置說明:

節點 說明
maven 構建項目或使用該插件所需要的 Maven 最低版本

4、issueManagement

issueManagement 元素用於描述項目的問題管理系統。

<issueManagement>
    <system>jira</system>
    <url>http://10.39.196.10:8080/banseon</url>
</issueManagement>

配置說明:

節點 說明
system 問題系統名稱
url 問題系統 URL

5、ciManagement

ciManagement 元素用於描述項目的持續集成系統。

<ciManagement>
    <system></system>
    <url></url>
    <notifiers>
        <notifier>
            <type></type>
            <sendOnError>true</sendOnError>
            <sendOnFailure>true</sendOnFailure>
            <sendOnSuccess>true</sendOnSuccess>
            <sendOnWarning>true</sendOnWarning>
            <address></address>
            <configuration/>
        </notifier>
    </notifiers>
</ciManagement>

配置說明:

節點 說明
system 集成系統名稱
url 集成系統 URL
notifiers 構建完成時,需通知的人員列表,包括被通知者信息和通知條件
notifiers/notifier 一個被通知人員配置信息
notifiers/notifier/type 使用何種方法通知
notifiers/notifier/sendOnError 發生錯誤時是否通知
notifiers/notifier/sendOnFailure 構建失敗時是否通知
notifiers/notifier/sendOnSuccess 構建成功時是否通知
notifiers/notifier/sendOnWarning 發生警告時是否通知
notifiers/notifier/address 通知發送到哪裡,該配置已過期
notifiers/notifier/configuration 擴展配置項

6、mailingLists

mailingLists 元素用於描述項目相關的郵件信息。

<mailingLists>
    <mailingList>
        <name>jack</name>
        <post>[email protected]</post>
        <subscribe>[email protected]</subscribe>
        <unsubscribe>[email protected]</unsubscribe>
        <archive></archive>
    </mailingList>
</mailingLists>

配置說明:

節點 說明
mailingList 一個郵件信息
mailingList/name 郵件名稱
mailingList/post 用於接受外部信息的郵件地址或鏈接;如果是郵件地址,那麼在創建文檔時將自動創建一個 mailto 鏈接。
mailingList/subscribe 用於訂閱的郵件地址或鏈接;如果是郵件地址,那麼在創建文檔時將自動創建一個 mailto 鏈接。
mailingList/unsubscribe 用於取消訂閱的郵件地址或鏈接;如果是郵件地址,那麼在創建文檔時將自動創建一個 mailto 鏈接。
mailingList/archive 可以瀏覽郵件信息的 URL

7、licenses

licenses 元素用於列出該項目的 license 列表。

<licenses>
    <license>
        <name>The Apache Software License, Version 2.0</name>
        <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
        <comments></comments>
    </license>
</licenses>

配置說明:

節點 說明
license 表示一個 license
name license 的名稱
url license 頁面 URL
distribution 項目的分發方式:repo,可以從 Maven 倉庫下載;manual 用戶須手動下載和安裝依賴
comments license 的補充信息

8、developers

developers 用於列出項目開發者。

<developers>
    <developer>
        <id>123</id>
        <name>abc</name>
        <email>[email protected]</email>
        <url>https://www.abc.com</url>
        <roles>
            <role>Project Manager</role>
        </roles>
        <organization>xyz</organization>
        <organizationUrl>https://www.xyz.com</organizationUrl>
        <properties>
            <dept>aa</dept>
        </properties>
        <timezone>8</timezone>
    </developer>
</developers>

配置說明:

節點 說明
developer 表示一個開發者
id 項目開發者的 id
name 項目開發者的姓名
email 項目開發者的 email
url 項目開發者的個人主頁
roles、role 項目開發者在項目中扮演的角色
organization 項目開發者所屬組織
organizationUrl 項目開發者所屬組織的 URL
properties 項目開發者屬性
timezone 項目開發者所在時區,-11 到 12 範圍內的整數

9、contributors

contributors 元素描述尚未成為提交者的項目貢獻者。

<contributors>
    <contributor>
        <name>abc</name>
        <email>[email protected]</email>
        <url>https://www.abc.com</url>
        <roles>
            <role>Project Tester</role>
        </roles>
        <organization>xyz</organization>
        <organizationUrl>https://www.xyz.com</organizationUrl>
        <properties>
            <dept>aa</dept>
        </properties>
        <timezone>8</timezone>
    </contributor>
</contributors>

配置說明:

節點 說明
contributor 表示一個貢獻者
name 貢獻者的姓名
email 貢獻者的 email
url 貢獻者的個人主頁
roles、role 貢獻者在項目中扮演的角色
organization 貢獻者所屬組織
organizationUrl 貢獻者所屬組織的 URL
properties 貢獻者屬性
timezone 貢獻者所在時區,-11 到 12 範圍內的整數

10、scm

SCM(Source Control Management)元素用於配置項目的代碼庫。

<scm>
    <url>https://github.com/abc/abc-common</url>
    <connection>https://github.com/abc/abc-common.git</connection>
    <developerConnection>https://github.com/abc/abc-common-dev.git</developerConnection>
    <tag></tag>
</scm>

配置說明:

節點 說明
url 可瀏覽代碼庫的 URL
connection 可以連接到代碼庫的 URL,該連接只讀
developerConnection 開發者連接到代碼庫的 URL,該連接可寫
tag 當前代碼的標簽,在開發階段預設為 HEAD

11、organization

organization 元素用於描述項目所屬組織。

節點 說明
name 組織的全名
url 組織的主頁 URL

12、properties

properties 用於定義鍵值對。

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>5.2.24.RELEASE</spring.version>
</properties>

13、dependencies

dependencies 用於定義項目的依賴。

<dependencies>
    <dependency>
        <groupId>com.abc</groupId>
        <artifactId>commons</artifactId>
        <version>1.0.0</version>
        <type>jar</type>
        <classifier></classifier>
        <scope>compile</scope>
        <!--systemPath></systemPath-->
        <exclusions>
            <exclusion>
                <groupId>com.xyz</groupId>
                <artifactId>xxx</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <optional>true</optional>
</dependencies>

配置說明:

節點 說明
dependency 表示一個依賴
groupId 依賴工程組標識
artifactId 依賴工程標識
version 依賴工程版本
type 依賴類型,預設為 jar;它通常表示依賴文件的擴展名
classifier 依賴的分類器,它可以區分屬於同一個 POM,但不同構建方式生成的構件。分類器名被附加到文件名的版本號後面。
scope 依賴範圍,可以為:compile、test、runtime、provided、system;預設為:compile
systemPath 僅供 system 範圍使用。該元素為依賴指定了文件系統上的路徑,需要絕對路徑而不是相對路徑。
exclusions 排除該依賴工程不需要的依賴
exclusion 表示一個排除的依賴。groupId:排除的依賴工程組標識;artifactId:排除的依賴工程標識,可以用 * 表示任意個字元
optional 可選依賴,它阻斷依賴的傳遞性。對於該依賴的依賴將不會被引入。

14、dependencyManagement

dependencyManagement 元素用於對依賴進行管理;這部分的依賴信息不會被立即解析,而是當在 dependencies 中聲明一個依賴(groupId 和 artifactId 必須),如果 groupId 和 artifactId 以外的一些信息沒有描述,則通過 groupId 和 artifactId 匹配到這裡的依賴,並使用這裡的依賴信息。

<dependencyManagement>
    <dependencies>
        <dependency>
            ...
        </dependency>
    </dependencies>
</dependencyManagement>

15、modules

<modules>
    <module>module-a</module>
    <module>module-b</module>
    <module>module-c</module>
</modules>

modules 元素用於列出項目的模塊(子項目)。

配置說明:

節點 說明
module 一個模塊,元素值為指向該模塊的相對路徑

16、reporting

reporting 元素用於生成報表,當執行"mvn site",報表就會按照配置生成。

<reporting>
    <excludeDefaults>false</excludeDefaults>
    <outputDirectory>${project.build.directory}/site</outputDirectory>
    <plugins>
        <plugin>
            <groupId>com.abc</groupId>
            <artifactId>xyz</artifactId>
            <version>1.0.0</version>
            <inherited>true</inherited>
            <configuration></configuration>
            <reportSets>
                <reportSet>
                    <id>123</id>
                    <configuration/>
                    <inherited>true</inherited>
                    <reports>
                        <report></report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

配置說明:

節點 說明
excludeDefaults 是否排除預設報表,預設:false
outputDirectory 報表生成目錄,預設:${project.build.directory}/site
plugins 報表插件列表
plugins/plugin 一個報表插件
plugins/plugin/groupId 插件 groupId
plugins/plugin/artifactId 插件 artifactId
plugins/plugin/version 插件版本
plugins/plugin/inherited 配置是否傳播到子 POM
plugins/plugin/configuration 插件配置
plugins/plugin/reportSets 報表規範列表,每個規範(可能)具有不同的配置,一個規範(報表集)對應一個執行目標
plugins/plugin/reportSets/reportSet 一個報表規範
plugins/plugin/reportSets/reportSet/id 報表規範唯一標識符
plugins/plugin/reportSets/reportSet/configuration 報表規範配置
plugins/plugin/reportSets/reportSet/inherited 配置是否傳播到子 POM
plugins/plugin/reportSets/reportSet/reports 該規範使用到的報表列表
plugins/plugin/reportSets/reportSet/reports/report 一個報表

17、build

build 元素用於描述項目如何構建。

<build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <scriptSourceDirectory></scriptSourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <outputDirectory>target/classes</outputDirectory>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
    <directory>target</directory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <defaultGoal>clean package</defaultGoal>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>*.xml</include>
            </includes>
            <excludes>
                <exclude>*.abc</exclude>
            </excludes>
            <targetPath></targetPath>
            <filtering>false</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <includes>
                <include>*.xml</include>
            </includes>
            <excludes>
                <exclude>*.abc</exclude>
            </excludes>
            <targetPath></targetPath>
            <filtering>false</filtering>
        </testResource>
    </testResources>
    <filters>
        <filter></filter>
    </filters>
    <extensions>
        <extension>
            <groupId>com.abc</groupId>
            <artifactId>my-extension</artifactId>
            <version>1.0.0</version>
        </extension>
    </extensions>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.2.1</version>
            <extensions>false</extensions>
            <executions>
                <execution>
                    <id>attach-source</id>
                    <phase></phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                    <inherited>true</inherited>
            

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 不說廢話,直接上乾貨: (註意大小寫:object為對象,Object為類) 1,object.getClass()它是Object類的實例方法,返回一個對象運行時的類的Class對象,換句話說,它返回的是對象具體類型的類對象。 2,Object.class 這是java語言的一種語法糖,用來返回一 ...
  • # 前言 最近針對java項目的部署方式進行整理,jenkins/tomcat/windows工具/linux腳本/web部署平臺等等 發現war包通過tomcat部署比較繁瑣,等待時間長,配置規則複雜對於小白很不友好,也難以接入到自定義的部署工具/平臺中 之前開發的Jar包部署平臺是servlet ...
  • 數組索引是指在`numpy`數組中引用特定元素的方法。`numpy`的數組索引又稱為`fancy indexing`,比其他編程語言的索引強大很多。 # 1. 選取數據 numpy的索引除了像其他語言一樣選擇一個元素,還可以間隔著選取多個元素,也可以用任意的順序選取元素。 比如一維數組: ```py ...
  • urllib+BeautifulSoup爬取並解析2345天氣王歷史天氣數據 網址:[東城歷史天氣查詢_歷史天氣預報查詢_2345天氣預報](https://tianqi.2345.com/wea_history/71445.htm) ![image-20230702161423470](https ...
  • # 數列分段 Section II ## 題目描述 對於給定的一個長度為N的正整數數列 $A_{1\sim N}$,現要將其分成 $M$($M\leq N$)段,並要求每段連續,且每段和的最大值最小。 關於最大值最小: 例如一數列 $4\ 2\ 4\ 5\ 1$ 要分成 $3$ 段。 將其如下分段: ...
  • 本文通過閱讀Spring源碼,分析Bean實例化流程。 # Bean實例化入口 上一篇文章已經介紹,Bean實例化入口在AbstractApplicationContext類的finishBeanFactoryInitialization方法: ```java protected void fini ...
  • # 1、Java常用插件實現方案 ## 1.2、serviceloader方式 serviceloader是java提供的spi模式的實現。按照介面開發實現類,而後配置,java通過ServiceLoader來實現統一介面不同實現的依次調用。而java中最經典的serviceloader的使用就是J ...
  • **原文鏈接:** [Go 語言 context 都能做什麼?](https://mp.weixin.qq.com/s/7IliODEUt3JpEuzL8K_sOg) 很多 Go 項目的源碼,在讀的過程中會發現一個很常見的參數 `ctx`,而且基本都是作為函數的第一個參數。 為什麼要這麼寫呢?這個參 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...