<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>...</groupId> <artifactId>...</artifactId> <version>...</version> <packaging>...</packaging> <!-- 依賴配置 --> <dependencies>...</dependencies> <parent>...</parent> <dependencyManagement>...</dependencyManagement> <modules>...</modules> <properties>...</properties> <!-- 構建配置 --> <build>...</build> <reporting>...</reporting> <!-- 項目信息 --> <name>...</name> <description>...</description> <url>...</url> <inceptionYear>...</inceptionYear> <licenses>...</licenses> <organization>...</organization> <developers>...</developers> <contributors>...</contributors> <!-- 環境設置 --> <issueManagement>...</issueManagement> <ciManagement>...</ciManagement> <mailingLists>...</mailingLists> <scm>...</scm> <prerequisites>...</prerequisites> <repositories>...</repositories> <pluginRepositories>...</pluginRepositories> <distributionManagement>...</distributionManagement> <profiles>...</profiles> </project>
1.基本參數解釋html
modelVersion:pom模型版本,maven2和3只能爲4.0.0
groupId:組ID,maven用於定位
artifactId:在組中的惟一ID用於定位
version:項目版本
packaging:項目打包方式,有如下值:pom, jar, maven-plugin, ejb, war, ear, rar, parjava
2.依賴參數解釋web
<parent> <groupId>com.learnPro</groupId> <artifactId>SIP-parent</artifactId> <relativePath></relativePath> <version>0.0.1-SNAPSHOT</version> </parent>
groupId:父項目的構件標識符
artifactId:父項目的惟一標識符
relativePath:Maven首先在當前項目的找父項目的pom,而後在文件系統的這個位置(relativePath),而後在本地倉庫,再在遠程倉庫找。
version:父項目的版本apache
<modules> <module>com-a</> <module>com-b</> <module>com-c</> </modules>
用於指定當前項目所包含的全部模塊。以後對這個項目進行的maven操做,會讓全部子模塊也進行相同操做。maven
<properties> <java.version>1.7</java.version> </properties>
能夠在pom文件的任意地方經過${java.version}來引用ide
<dependencies> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> <type></type> <optional></optional> <!-- optional 可選,不會傳遞依賴--> <scope></scope> <classifier></classifier> <systemPath></systemPath> <exclusions></exclusions> </dependency> </dependencies>
引入依賴jar包,子項目會自動引用。svn
<dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement>
在父項目中使用dependencyManagement,子項目不會自動引入對應包,須要手動引用但這時候能夠不指定版本,這樣就實現了對版本的統一。佈局
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency>
3.構建參加詳解post
用於配置項目構建相關信息性能
<build> <!--該元素設置了項目源碼目錄,當構建項目的時候,構建系統會編譯目錄裏的源碼。該路徑是相對於pom.xml的相對路徑。--> <sourceDirectory/> <!--該元素設置了項目腳本源碼目錄,該目錄和源碼目錄不一樣:絕大多數狀況下,該目錄下的內容 會被拷貝到輸出目錄(由於腳本是被解釋的,而不是被編譯的)。--> <scriptSourceDirectory/> <!--該元素設置了項目單元測試使用的源碼目錄,當測試項目的時候,構建系統會編譯目錄裏的源碼。該路徑是相對於pom.xml的相對路徑。--> <testSourceDirectory/> <!--被編譯過的應用程序class文件存放的目錄。--> <outputDirectory/> <!--被編譯過的測試class文件存放的目錄。--> <testOutputDirectory/> <!--使用來自該項目的一系列構建擴展--> <extensions> <!--描述使用到的構建擴展。--> <extension> <!--構建擴展的groupId--> <groupId/> <!--構建擴展的artifactId--> <artifactId/> <!--構建擴展的版本--> <version/> </extension> </extensions> <!--當項目沒有規定目標(Maven2 叫作階段)時的默認值--> <defaultGoal/> <!--這個元素描述了項目相關的全部資源路徑列表,例如和項目相關的屬性文件,這些資源被包含在最終的打包文件裏。--> <resources> <!--這個元素描述了項目相關或測試相關的全部資源路徑--> <resource> <!-- 描述了資源的目標路徑。該路徑相對target/classes目錄(例如${project.build.outputDirectory})。舉個例 子,若是你想資源在特定的包裏(org.apache.maven.messages),你就必須該元素設置爲org/apache/maven /messages。然而,若是你只是想把資源放到源碼目錄結構裏,就不須要該配置。--> <targetPath/> <!--是否使用參數值代替參數名。參數值取自properties元素或者文件裏配置的屬性,文件在filters元素裏列出。--> <filtering/> <!--描述存放資源的目錄,該路徑相對POM路徑--> <directory/> <!--包含的模式列表,例如**/*.xml.--> <includes/> <!--排除的模式列表,例如**/*.xml--> <excludes/> </resource> </resources> <!--這個元素描述了單元測試相關的全部資源路徑,例如和單元測試相關的屬性文件。--> <testResources> <!--這個元素描述了測試相關的全部資源路徑,參見build/resources/resource元素的說明--> <testResource> <targetPath/><filtering/><directory/><includes/><excludes/> </testResource> </testResources> <!--構建產生的全部文件存放的目錄--> <directory/> <!--產生的構件的文件名,默認值是${artifactId}-${version}。--> <finalName/> <!--當filtering開關打開時,使用到的過濾器屬性文件列表--> <filters/> <!--子項目能夠引用的默認插件信息。該插件配置項直到被引用時纔會被解析或綁定到生命週期。給定插件的任何本地配置都會覆蓋這裏的配置--> <pluginManagement> <!--使用的插件列表 。--> <plugins> <!--plugin元素包含描述插件所須要的信息。--> <plugin> <!--插件在倉庫裏的group ID--> <groupId/> <!--插件在倉庫裏的artifact ID--> <artifactId/> <!--被使用的插件的版本(或版本範圍)--> <version/> <!--是否從該插件下載Maven擴展(例如打包和類型處理器),因爲性能緣由,只有在真須要下載時,該元素才被設置成enabled。--> <extensions/> <!--在構建生命週期中執行一組目標的配置。每一個目標可能有不一樣的配置。--> <executions> <!--execution元素包含了插件執行須要的信息--> <execution> <!--執行目標的標識符,用於標識構建過程當中的目標,或者匹配繼承過程當中須要合併的執行目標--> <id/> <!--綁定了目標的構建生命週期階段,若是省略,目標會被綁定到源數據裏配置的默認階段--> <phase/> <!--配置的執行目標--> <goals/> <!--配置是否被傳播到子POM--> <inherited/> <!--做爲DOM對象的配置--> <configuration/> </execution> </executions> <!--項目引入插件所須要的額外依賴--> <dependencies> <!--參見dependencies/dependency元素--> <dependency> ...... </dependency> </dependencies> <!--任何配置是否被傳播到子項目--> <inherited/> <!--做爲DOM對象的配置--> <configuration/> </plugin> </plugins> </pluginManagement> <!--使用的插件列表--> <plugins> <!--參見build/pluginManagement/plugins/plugin元素--> <plugin> <groupId/><artifactId/><version/><extensions/> <executions> <execution> <id/><phase/><goals/><inherited/><configuration/> </execution> </executions> <dependencies> <!--參見dependencies/dependency元素--> <dependency> ...... </dependency> </dependencies> <goals/><inherited/><configuration/> </plugin> </plugins> </build>
<reporting> <!--true,則,網站不包括默認的報表。這包括「項目信息」菜單中的報表。--> <excludeDefaults/> <!--全部產生的報表存放到哪裏。默認值是${project.build.directory}/site。--> <outputDirectory/> <!--使用的報表插件和他們的配置。--> <plugins> <!--plugin元素包含描述報表插件須要的信息--> <plugin> <!--報表插件在倉庫裏的group ID--> <groupId/> <!--報表插件在倉庫裏的artifact ID--> <artifactId/> <!--被使用的報表插件的版本(或版本範圍)--> <version/> <!--任何配置是否被傳播到子項目--> <inherited/> <!--報表插件的配置--> <configuration/> <!--一組報表的多重規範,每一個規範可能有不一樣的配置。一個規範(報表集)對應一個執行目標 。例如,有1,2,3,4,5,6,7,8,9個報表。1,2,5構成A報表集,對應一個執行目標。2,5,8構成B報表集,對應另外一個執行目標--> <reportSets> <!--表示報表的一個集合,以及產生該集合的配置--> <reportSet> <!--報表集合的惟一標識符,POM繼承時用到--> <id/> <!--產生報表集合時,被使用的報表的配置--> <configuration/> <!--配置是否被繼承到子POMs--> <inherited/> <!--這個集合裏使用到哪些報表--> <reports/> </reportSet> </reportSets> </plugin> </plugins> </reporting>
4.項目信息參數解釋
name:給用戶提供更爲友好的項目名
description:項目描述,maven文檔中保存
url:主頁的URL,maven文檔中保存
inceptionYear:項目建立年份,4位數字。當產生版權信息時須要使用這個值
licenses:該元素描述了項目全部License列表。 應該只列出該項目的license列表,不要列出依賴項目的license列表。若是列出多個license,用戶能夠選擇它們中的一個而不是接受全部license。(以下)
<license> <!--license用於法律上的名稱--> <name>...</name> <!--官方的license正文頁面的URL--> <url>....</url> <!--項目分發的主要方式:repo,能夠從Maven庫下載 manual, 用戶必須手動下載和安裝依賴--> <distribution>repo</distribution> <!--關於license的補充信息--> <comments>....</comments> </license>
organization:1.name組織名2.url組織主頁url
developers:項目開發人員列表(以下)
contributors:項目其餘貢獻者列表,同developers
<developers> <!--某個開發者信息--> <developer> <!--開發者的惟一標識符--> <id>....</id> <!--開發者的全名--> <name>...</name> <!--開發者的email--> <email>...</email> <!--開發者的主頁--> <url>...<url/> <!--開發者在項目中的角色--> <roles> <role>Java Dev</role> <role>Web UI</role> </roles> <!--開發者所屬組織--> <organization>sun</organization> <!--開發者所屬組織的URL--> <organizationUrl>...</organizationUrl> <!--開發者屬性,如即時消息如何處理等--> <properties> <!-- 和主標籤中的properties同樣,能夠隨意定義子標籤 --> </properties> <!--開發者所在時區, -11到12範圍內的整數。--> <timezone>-5</timezone> </developer> </developers>
5.環境設置參數
<issueManagement> <system>Bugzilla</system> <url>http://127.0.0.1/bugzilla/</url> </issueManagement>
system:系統類型
url:路徑
<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> <address>continuum@127.0.0.1</address> <configuration></configuration> </notifier> </notifiers> </ciManagement>
system:持續集成系統的名字
url:持續集成系統的URL
notifiers:構建完成時,須要通知的開發者/用戶的配置項。包括被通知者信息和通知條件(錯誤,失敗,成功,警告)
type:通知方式
sendOnError:錯誤時是否通知
sendOnFailure:失敗時是否通知
sendOnSuccess:成功時是否通知
sendOnWarning:警告時是否通知
address:通知發送到的地址
configuration:擴展項
這裏本身單獨會寫一篇文章講maven的持續集成
<mailingLists> <mailingList> <name>User List</name> <subscribe>user-subscribe@127.0.0.1</subscribe> <unsubscribe>user-unsubscribe@127.0.0.1</unsubscribe> <post>user@127.0.0.1</post> <archive>http://127.0.0.1/user/</archive> <otherArchives> <otherArchive>http://base.google.com/base/1/127.0.0.1</otherArchive> </otherArchives> </mailingList> ..... </mailingLists>
subscribe, unsubscribe: 訂閱郵件(取消訂閱)的地址或連接,若是是郵件地址,建立文檔時,mailto:連接會被自動建立
archive:瀏覽郵件信息的URL
post:接收郵件的地址
<scm> <connection>scm:svn:http://127.0.0.1/svn/my-project</connection> <developerConnection>scm:svn:https://127.0.0.1/svn/my-project</developerConnection> <tag>HEAD</tag> <url>http://127.0.0.1/websvn/my-project</url> </scm>
connection, developerConnection:這兩個表示咱們如何鏈接到maven的版本庫。connection只提供讀,developerConnection將提供寫的請求
寫法如:scm:[provider]:[provider_specific]
若是鏈接到CVS倉庫,能夠配置以下:scm:cvs:pserver:127.0.0.1:/cvs/root:my-project
tag:項目標籤,默認HEAD
url:共有倉庫路徑
<prerequisites> <maven>2.0.6</maven> </prerequisites>
構建該項目或使用該插件所須要的Maven的最低版本
<repositories> <repository> <releases> <enabled>false</enabled> <updatePolicy>always</updatePolicy> <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> <layout>default</layout> </repository> </repositories> <pluginRepositories> ... </pluginRepositories>
releases, snapshots:這是各類構件的策略,release或者snapshot。這兩個集合,POM就能夠根據獨立倉庫任意類型的依賴改變策略。如:一我的可能只激活下載snapshot用來開發。
enable:true或者false,決定倉庫是否對於各自的類型激活(release或者snapshot)。
updatePolicy: 這個元素決定更新頻率。maven將比較本地pom的時間戳(存儲在倉庫的maven數據文件中)和遠程的.有如下選擇: always, daily (默認), interval:X (x是表明分鐘的整型),never.
checksumPolicy:當Maven向倉庫部署文件的時候,它也部署了相應的校驗和文件。可選的爲:ignore,fail,warn,或者不正確的校驗和。
layout:在上面描述倉庫的時候,提到他們有統一的佈局。Maven 2有它倉庫默認佈局。然而,Maven 1.x有不一樣佈局。使用這個元素來代表它是default仍是legacy。
<distributionManagement> ... <downloadUrl>http://mojo.codehaus.org/my-project</downloadUrl> <status>deployed</status> </distributionManagement>
管理的分佈在整個構建過程生成的工件和支持文件
downloadUrl: 其餘pom能夠經過此url的倉庫抓取組件
status:給出該構件在遠程倉庫的狀態
none: 默認
converted: 將被早期Maven 2 POM轉換過來
partner: 這個項目會從合做者倉庫同步過來
deployed: 從Maven 2或3實例部署
verified: 被覈實時正確的和最終的
<distributionManagement> <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>
指定Maven pom從遠程下載控件到當前項目的位置和方式,若是snapshotRepository沒有被定義則使用repository相關的配置
id, name:倉庫的惟一標識
uniqueVersion:true或false,指明控件部署的時候是否獲取獨立的版本號。
url:repository元素的核心。指定位置和部署協議發佈控件到倉庫。
layout:佈局,default或legacy
<distributionManagement> ... <site> <id>mojo.website</id> <name>Mojo Website</name> <url>scp://beaver.codehaus.org/home/projects/mojo/public_html/</url> </site> ... </distributionManagement>
多分佈存儲庫,distributionManagement負責定義如何部署項目的網站和文檔。
id, name, url: 這些元素與distributionManagement repository中的相同
<distributionManagement> ... <relocation> <groupId>org.apache</groupId> <artifactId>my-project</artifactId> <version>1.0</version> <message>We have moved the Project underApache</message> </relocation> ... </distributionManagement>
從新部署-項目不是靜態的,是活的。他們須要被搬到更合適的地方。如:當你的下個成功的開源項目移到Apache下,重命名爲org.apache:my-project:1.0對你項目更有好處。
<profiles> <profile> <!-- 本地開發環境 --> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <!-- 設置默認激活這個配置 --> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <!-- 發佈環境 --> <id>release</id> <properties> <profiles.active>release</profiles.active> </properties> </profile> <profile> <!-- 測試環境 --> <id>beta</id> <properties> <profiles.active>beta</profiles.active> </properties> </profile> </profiles>
profile可讓咱們定義一系列的配置信息(插件等),而後指定其激活條件
jdk:檢測到對應jdk版本就激活
os:針對不一樣操做系統
property:當maven檢測到property(pom中如${name}這樣的)profile將被激活
file:若是存在文件,激活,不存在文件激活
qq技術交流羣:208779755 我的公衆號:海濤聊技術