maven provided_Maven 教程之 pom.xml 详解
點擊上方“Java知音”,選擇“置頂公眾號”
技術文章第一時間送達!
作者:dunwu
https://github.com/dunwu/blog
推薦閱讀(點擊即可跳轉閱讀)
1.?SpringBoot內容聚合
2.?面試題內容聚合
3.?設計模式內容聚合
4.?Mybatis內容聚合
5.?多線程內容聚合
簡介
什么是 pom?
POM 是 Project Object Model 的縮寫,即項目對象模型。
pom.xml 就是 maven 的配置文件,用以描述項目的各種信息。
pom 配置一覽
<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.0modelVersion>
??
??<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>
基本配置
project?-?project?是 pom.xml 中描述符的根。
modelVersion?-?modelVersion?指定 pom.xml 符合哪個版本的描述符。maven 2 和 3 只能為 4.0.0。
一般 jar 包被識別為:?groupId:artifactId:version?的形式。
<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.0modelVersion>
??<groupId>org.codehaus.mojogroupId>
??<artifactId>my-projectartifactId>
??<version>1.0version>
??<packaging>warpackaging>
project>
maven 坐標
在 maven 中,根據?groupId、artifactId、version?組合成?groupId:artifactId:version?來唯一識別一個 jar 包。
groupId?- 團體、組織的標識符。團體標識的約定是,它以創建這個項目的組織名稱的逆向域名(reverse domain name)開頭。一般對應著 java 的包結構。
artifactId?- 單獨項目的唯一標識符。比如我們的 tomcat、commons 等。不要在 artifactId 中包含點號(.)。
version?- 一個項目的特定版本。
maven 有自己的版本規范,一般是如下定義 major version、minor version、incremental version-qualifier ,比如 1.2.3-beta-01。要說明的是,maven 自己判斷版本的算法是 major、minor、incremental 部分用數字比較,qualifier 部分用字符串比較,所以要小心 alpha-2 和 alpha-15 的比較關系,最好用 alpha-02 的格式。
maven 在版本管理時候可以使用幾個特殊的字符串 SNAPSHOT、LATEST、RELEASE。比如?1.0-SNAPSHOT。各個部分的含義和處理邏輯如下說明:
SNAPSHOT?- 這個版本一般用于開發過程中,表示不穩定的版本。
LATEST?- 指某個特定構件的最新發布,這個發布可能是一個發布版,也可能是一個 snapshot 版,具體看哪個時間最后。
RELEASE?:指最后一個發布版。
packaging?- 項目的類型,描述了項目打包后的輸出,默認是 jar。常見的輸出類型為:pom, jar, maven-plugin, ejb, war, ear, rar, par。
依賴配置
dependencies
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<dependencies>
????<dependency>
?????<groupId>org.apache.mavengroupId>
??????<artifactId>maven-embedderartifactId>
??????<version>2.0version>
??????<type>jartype>
??????<scope>testscope>
??????<optional>trueoptional>
??????<exclusions>
????????<exclusion>
??????????<groupId>org.apache.mavengroupId>
??????????<artifactId>maven-coreartifactId>
????????exclusion>
??????exclusions>
????dependency>
????...
??dependencies>
??...
project>
groupId,?artifactId,?version?- 和基本配置中的?groupId、artifactId、version?意義相同。
type?- 對應?packaging?的類型,如果不使用?type?標簽,maven 默認為 jar。
scope?- 此元素指的是任務的類路徑(編譯和運行時,測試等)以及如何限制依賴關系的傳遞性。有 5 種可用的限定范圍:
compile?- 如果沒有指定?scope?標簽,maven 默認為這個范圍。編譯依賴關系在所有 classpath 中都可用。此外,這些依賴關系被傳播到依賴項目。
provided?- 與 compile 類似,但是表示您希望 jdk 或容器在運行時提供它。它只適用于編譯和測試 classpath,不可傳遞。
runtime?- 此范圍表示編譯不需要依賴關系,而是用于執行。它是在運行時和測試 classpath,但不是編譯 classpath。
test?- 此范圍表示正常使用應用程序不需要依賴關系,僅適用于測試編譯和執行階段。它不是傳遞的。
system?- 此范圍與 provided 類似,除了您必須提供明確包含它的 jar。該 artifact 始終可用,并且不是在倉庫中查找。
systemPath?- 僅當依賴范圍是系統時才使用。否則,如果設置此元素,構建將失敗。該路徑必須是絕對路徑,因此建議使用?propertie?來指定特定的路徑,如\$ {java.home} / lib。由于假定先前安裝了系統范圍依賴關系,maven 將不會檢查項目的倉庫,而是檢查庫文件是否存在。如果沒有,maven 將會失敗,并建議您手動下載安裝。
optional?-?optional?讓其他項目知道,當您使用此項目時,您不需要這種依賴性才能正常工作。
exclusions?- 包含一個或多個排除元素,每個排除元素都包含一個表示要排除的依賴關系的?groupId?和?artifactId。與可選項不同,可能或可能不會安裝和使用,排除主動從依賴關系樹中刪除自己。
parent
maven 支持繼承功能。子 POM 可以使用?parent?指定父 POM ,然后繼承其配置。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??<modelVersion>4.0.0modelVersion>
??<parent>
????<groupId>org.codehaus.mojogroupId>
????<artifactId>my-parentartifactId>
????<version>2.0version>
????<relativePath>../my-parentrelativePath>
??parent>
??<artifactId>my-projectartifactId>
project>
relativePath?- 注意?relativePath?元素。在搜索本地和遠程存儲庫之前,它不是必需的,但可以用作 maven 的指示符,以首先搜索給定該項目父級的路徑。
dependencyManagement
dependencyManagement?是表示依賴 jar 包的聲明。即你在項目中的?dependencyManagement?下聲明了依賴,maven 不會加載該依賴,dependencyManagement?聲明可以被子 POM 繼承。
dependencyManagement?的一個使用案例是當有父子項目的時候,父項目中可以利用?dependencyManagement?聲明子項目中需要用到的依賴 jar 包,之后,當某個或者某幾個子項目需要加載該依賴的時候,就可以在子項目中?dependencies?節點只配置?groupId?和?artifactId?就可以完成依賴的引用。
dependencyManagement?主要是為了統一管理依賴包的版本,確保所有子項目使用的版本一致,類似的還有plugins和pluginManagement。
modules
子模塊列表。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??<modelVersion>4.0.0modelVersion>
??<groupId>org.codehaus.mojogroupId>
??<artifactId>my-parentartifactId>
??<version>2.0version>
??<packaging>pompackaging>
??<modules>
????<module>my-projectmodule>
????<module>another-projectmodule>
????<module>third-project/pom-example.xmlmodule>
??modules>
project>
properties
屬性列表。定義的屬性可以在 pom.xml 文件中任意處使用。使用方式為?${propertie}?。
<project>??...
??<properties>
????<maven.compiler.source>1.7<maven.compiler.source>
????<maven.compiler.target>1.7<maven.compiler.target>
????<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
????<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
??properties>
??...
project>
構建配置
build
build 可以分為 "project build" 和 "profile build"。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??
??<build>...build>
??<profiles>
????<profile>
??????
??????<build>...build>
????profile>
??profiles>
project>
基本構建配置:
<build>??<defaultGoal>installdefaultGoal>
??<directory>${basedir}/targetdirectory>
??<finalName>${artifactId}-${version}finalName>
??<filters>
????<filter>filters/filter1.propertiesfilter>
??filters>
??...
build>
defaultGoal?: 默認執行目標或階段。如果給出了一個目標,它應該被定義為它在命令行中(如 jar:jar)。如果定義了一個階段(如安裝),也是如此。
directory?:構建時的輸出路徑。默認為:${basedir}/target?。
finalName?:這是項目的最終構建名稱(不包括文件擴展名,例如:my-project-1.0.jar)
filter?:定義?* .properties?文件,其中包含適用于接受其設置的資源的屬性列表(如下所述)。換句話說,過濾器文件中定義的“name = value”對在代碼中替換\$ {name}字符串。
resources
資源的配置。資源文件通常不是代碼,不需要編譯,而是在項目需要捆綁使用的內容。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??<build>
????...
????<resources>
??????<resource>
????????<targetPath>META-INF/plexustargetPath>
????????<filtering>falsefiltering>
????????<directory>${basedir}/src/main/plexusdirectory>
????????<includes>
??????????<include>configuration.xmlinclude>
????????includes>
????????<excludes>
??????????<exclude>**/*.propertiesexclude>
????????excludes>
??????resource>
????resources>
????<testResources>
??????...
????testResources>
????...
??build>
project>
resources: 資源元素的列表,每個資源元素描述與此項目關聯的文件和何處包含文件。
targetPath: 指定從構建中放置資源集的目錄結構。目標路徑默認為基本目錄。將要包裝在 jar 中的資源的通常指定的目標路徑是 META-INF。
filtering: 值為 true 或 false。表示是否要為此資源啟用過濾。請注意,該過濾器?* .properties?文件不必定義為進行過濾 - 資源還可以使用默認情況下在 POM 中定義的屬性(例如\$ {project.version}),并將其傳遞到命令行中“-D”標志(例如,“-Dname = value”)或由 properties 元素顯式定義。過濾文件覆蓋上面。
directory: 值定義了資源的路徑。構建的默認目錄是${basedir}/src/main/resources。
includes: 一組文件匹配模式,指定目錄中要包括的文件,使用*作為通配符。
excludes: 與?includes?類似,指定目錄中要排除的文件,使用*作為通配符。注意:如果?include?和?exclude?發生沖突,maven 會以?exclude?作為有效項。
testResources:?testResources?與?resources?功能類似,區別僅在于:testResources?指定的資源僅用于 test 階段,并且其默認資源目錄為:${basedir}/src/test/resources?。
plugins
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??<build>
????...
????<plugins>
??????<plugin>
????????<groupId>org.apache.maven.pluginsgroupId>
????????<artifactId>maven-jar-pluginartifactId>
????????<version>2.6version>
????????<extensions>falseextensions>
????????<inherited>trueinherited>
????????<configuration>
??????????<classifier>testclassifier>
????????configuration>
????????<dependencies>...dependencies>
????????<executions>...executions>
??????plugin>
????plugins>
??build>
project>
groupId,?artifactId,?version?:和基本配置中的?groupId、artifactId、version?意義相同。
extensions?:值為 true 或 false。是否加載此插件的擴展名。默認為 false。
inherited?:值為 true 或 false。這個插件配置是否應該適用于繼承自這個插件的 POM。默認值為 true。
configuration?- 這是針對個人插件的配置,這里不擴散講解。
dependencies?:這里的?dependencies?是插件本身所需要的依賴。
executions?:需要記住的是,插件可能有多個目標。每個目標可能有一個單獨的配置,甚至可能將插件的目標完全綁定到不同的階段。執行配置插件的目標的執行。
id: 執行目標的標識。
goals: 像所有多元化的 POM 元素一樣,它包含單個元素的列表。在這種情況下,這個執行塊指定的插件目標列表。
phase: 這是執行目標列表的階段。這是一個非常強大的選項,允許將任何目標綁定到構建生命周期中的任何階段,從而改變 maven 的默認行為。
inherited: 像上面的繼承元素一樣,設置這個 false 會阻止 maven 將這個執行傳遞給它的子代。此元素僅對父 POM 有意義。
configuration: 與上述相同,但將配置限制在此特定目標列表中,而不是插件下的所有目標。
??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<build>
????<plugins>
??????<plugin>
????????<artifactId>maven-antrun-pluginartifactId>
????????<version>1.1version>
????????<executions>
??????????<execution>
????????????<id>echodirid>
????????????<goals>
??????????????<goal>rungoal>
????????????goals>
????????????<phase>verifyphase>
????????????<inherited>falseinherited>
????????????<configuration>
??????????????<tasks>
????????????????<echo>Build?Dir:?${project.build.directory}echo>
??????????????tasks>
????????????configuration>
??????????execution>
????????executions>
??????plugin>
????plugins>
??build>
project>
pluginManagement
與?dependencyManagement?很相似,在當前 POM 中僅聲明插件,而不是實際引入插件。子 POM 中只配置?groupId?和?artifactId?就可以完成插件的引用,且子 POM 有權重寫 pluginManagement 定義。
它的目的在于統一所有子 POM 的插件版本。
directories
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<build>
????<sourceDirectory>${basedir}/src/main/javasourceDirectory>
????<scriptSourceDirectory>${basedir}/src/main/scriptsscriptSourceDirectory>
????<testSourceDirectory>${basedir}/src/test/javatestSourceDirectory>
????<outputDirectory>${basedir}/target/classesoutputDirectory>
????<testOutputDirectory>${basedir}/target/test-classestestOutputDirectory>
????...
??build>
project>
目錄元素集合存在于?build?元素中,它為整個 POM 設置了各種目錄結構。由于它們在配置文件構建中不存在,所以這些不能由配置文件更改。
如果上述目錄元素的值設置為絕對路徑(擴展屬性時),則使用該目錄。否則,它是相對于基礎構建目錄:${basedir}。
extensions
擴展是在此構建中使用的 artifacts 的列表。它們將被包含在運行構建的 classpath 中。它們可以啟用對構建過程的擴展(例如為 Wagon 傳輸機制添加一個 ftp 提供程序),并使活動的插件能夠對構建生命周期進行更改。簡而言之,擴展是在構建期間激活的 artifacts。擴展不需要實際執行任何操作,也不包含 Mojo。因此,擴展對于指定普通插件接口的多個實現中的一個是非常好的。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<build>
????...
????<extensions>
??????<extension>
????????<groupId>org.apache.maven.wagongroupId>
????????<artifactId>wagon-ftpartifactId>
????????<version>1.0-alpha-3version>
??????extension>
????extensions>
????...
??build>
project>
reporting
報告包含特定針對?site?生成階段的元素。某些 maven 插件可以生成?reporting?元素下配置的報告,例如:生成 javadoc 報告。reporting?與?build?元素配置插件的能力相似。明顯的區別在于:在執行塊中插件目標的控制不是細粒度的,報表通過配置?reportSet?元素來精細控制。
而微妙的區別在于?reporting?元素下的?configuration?元素可以用作?build?下的?configuration?,盡管相反的情況并非如此(?build?下的?configuration?不影響?reporting?元素下的?configuration?)。
另一個區別就是?plugin?下的?outputDirectory?元素。在報告的情況下,默認輸出目錄為?${basedir}/target/site。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<reporting>
????<plugins>
??????<plugin>
????????...
????????<reportSets>
??????????<reportSet>
????????????<id>sunlinkid>
????????????<reports>
??????????????<report>javadocreport>
????????????reports>
????????????<inherited>trueinherited>
????????????<configuration>
??????????????<links>
????????????????<link>http://java.sun.com/j2se/1.5.0/docs/api/link>
??????????????links>
????????????configuration>
??????????reportSet>
????????reportSets>
??????plugin>
????plugins>
??reporting>
??...
project>
項目信息
項目信息相關的這部分標簽都不是必要的,也就是說完全可以不填寫。
它的作用僅限于描述項目的詳細信息。
下面的示例是項目信息相關標簽的清單:
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??
??
??<name>maven-notesname>
??
??<description>maven?學習筆記description>
??
??<url>https://github.com/dunwu/maven-notesurl>
??
??<inceptionYear>2017inceptionYear>
??
??<licenses>
????<license>
??????<name>Apache?License,?Version?2.0name>
??????<url>https://www.apache.org/licenses/LICENSE-2.0.txturl>
??????<distribution>repodistribution>
??????<comments>A?business-friendly?OSS?licensecomments>
????license>
??licenses>
??
??<organization>
????<name>...name>
????<url>...url>
??organization>
??
??<developers>
????<developer>
??????<id>victorid>
??????<name>Zhang?Pengname>
??????<email>forbreak?at?163.comemail>
??????<url>https://github.com/dunwuurl>
??????<organization>...organization>
??????<organizationUrl>...organizationUrl>
??????<roles>
????????<role>architectrole>
????????<role>developerrole>
??????roles>
??????<timezone>+8timezone>
??????<properties>...properties>
????developer>
??developers>
??
???<contributors>
????<contributor>
??????
????contributor>
??contributors>
??
??...
project>
這部分標簽都非常簡單,基本都能做到顧名思義,且都屬于可有可無的標簽,所以這里僅簡單介紹一下:
name?- 項目完整名稱
description?- 項目描述
url?- 一般為項目倉庫的 host
inceptionYear?- 開發年份
licenses?- 開源協議
organization?- 項目所屬組織信息
developers?- 項目開發者列表
contributors?- 項目貢獻者列表,?的子標簽和?的完全相同。
環境配置
issueManagement
這定義了所使用的缺陷跟蹤系統(Bugzilla,TestTrack,ClearQuest 等)。雖然沒有什么可以阻止插件使用這些信息的東西,但它主要用于生成項目文檔。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<issueManagement>
????<system>Bugzillasystem>
????<url>http://127.0.0.1/bugzilla/url>
??issueManagement>
??...
project>
ciManagement
CI 構建系統配置,主要是指定通知機制以及被通知的郵箱。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<ciManagement>
????<system>continuumsystem>
????<url>http://127.0.0.1:8080/continuumurl>
????<notifiers>
??????<notifier>
????????<type>mailtype>
????????<sendOnError>truesendOnError>
????????<sendOnFailure>truesendOnFailure>
????????<sendOnSuccess>falsesendOnSuccess>
????????<sendOnWarning>falsesendOnWarning>
????????<configuration><address>continuum@127.0.0.1address>configuration>
??????notifier>
????notifiers>
??ciManagement>
??...
project>
mailingLists
郵件列表
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<mailingLists>
????<mailingList>
??????<name>User?Listname>
??????<subscribe>user-subscribe@127.0.0.1subscribe>
??????<unsubscribe>user-unsubscribe@127.0.0.1unsubscribe>
??????<post>user@127.0.0.1post>
??????<archive>http://127.0.0.1/user/archive>
??????<otherArchives>
????????<otherArchive>http://base.google.com/base/1/127.0.0.1otherArchive>
??????otherArchives>
????mailingList>
??mailingLists>
??...
project>
scm
SCM(軟件配置管理,也稱為源代碼/控制管理或簡潔的版本控制)。常見的 scm 有 svn 和 git 。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<scm>
????<connection>scm:svn:http://127.0.0.1/svn/my-projectconnection>
????<developerConnection>scm:svn:https://127.0.0.1/svn/my-projectdeveloperConnection>
????<tag>HEADtag>
????<url>http://127.0.0.1/websvn/my-projecturl>
??scm>
??...
project>
prerequisites
POM 執行的預設條件。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<prerequisites>
????<maven>2.0.6maven>
??prerequisites>
??...
project>
repositories
repositories?是遵循 Maven 存儲庫目錄布局的 artifacts 集合。默認的 Maven 中央存儲庫位于https://repo.maven.apache.org/maven2/上。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<repositories>
????<repository>
??????<releases>
????????<enabled>falseenabled>
????????<updatePolicy>alwaysupdatePolicy>
????????<checksumPolicy>warnchecksumPolicy>
??????releases>
??????<snapshots>
????????<enabled>trueenabled>
????????<updatePolicy>neverupdatePolicy>
????????<checksumPolicy>failchecksumPolicy>
??????snapshots>
??????<id>codehausSnapshotsid>
??????<name>Codehaus?Snapshotsname>
??????<url>http://snapshots.maven.codehaus.org/maven2url>
??????<layout>defaultlayout>
????repository>
??repositories>
??<pluginRepositories>
????...
??pluginRepositories>
??...
project>
pluginRepositories
與?repositories?差不多。
<project?xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<distributionManagement>
????...
????<downloadUrl>http://mojo.codehaus.org/my-projectdownloadUrl>
????<status>deployedstatus>
??distributionManagement>
??...
project>
distributionManagement
它管理在整個構建過程中生成的 artifact 和支持文件的分布。從最后的元素開始:
<project?xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<distributionManagement>
????...
????<downloadUrl>http://mojo.codehaus.org/my-projectdownloadUrl>
????<status>deployedstatus>
??distributionManagement>
??...
project>
repository?- 與?repositories?相似
site?- 站點信息
relocation?- 項目遷移位置
profiles
activation?是一個?profile?的關鍵。配置文件的功能來自于在某些情況下僅修改基本 POM 的功能。這些情況通過?activation?元素指定。
<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??????????????????????https://maven.apache.org/xsd/maven-4.0.0.xsd">
??...
??<profiles>
????<profile>
??????<id>testid>
??????<activation>
????????<activeByDefault>falseactiveByDefault>
????????<jdk>1.5jdk>
????????<os>
??????????<name>Windows?XPname>
??????????<family>Windowsfamily>
??????????<arch>x86arch>
??????????<version>5.1.2600version>
????????os>
????????<property>
??????????<name>sparrow-typename>
??????????<value>Africanvalue>
????????property>
????????<file>
??????????<exists>${basedir}/file2.propertiesexists>
??????????<missing>${basedir}/file1.propertiesmissing>
????????file>
??????activation>
??????...
????profile>
??profiles>
project>
參考資料
https://maven.apache.org/pom.html
覺得不錯?歡迎轉發分享給更多人
總結
以上是生活随笔為你收集整理的maven provided_Maven 教程之 pom.xml 详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精子不液化会导致男性不育发生吗
- 下一篇: 深宅剧情介绍