經(jīng)過Maven生命周期的學(xué)習(xí),我們知道在Maven core中僅僅定義了抽象的生命周期,具體的實(shí)現(xiàn)是由插件完成的,而插件是以獨(dú)立的構(gòu)件形式存在。
在進(jìn)一步了解插件和生命周期的綁定關(guān)系之前,我們先了解一下插件目標(biāo)(Plugin Goal)的概念。
一個(gè)插件往往能夠完成多個(gè)功能。如果我們?yōu)槠渲忻總€(gè)功能都實(shí)現(xiàn)一個(gè)獨(dú)立的插件,顯然不可取的,因?yàn)檫@些功能背后有很多可以復(fù)用的代碼。因此,這些功能都聚集在一個(gè)插件里,每個(gè)功能就是一個(gè)插件目標(biāo)。例如maven-dependency-plugin有十幾個(gè)目標(biāo),分析項(xiàng)目依賴dependency:analyze,列出項(xiàng)目的依賴樹dependency:tree,列出項(xiàng)目所有已解析的依賴dependency:list。這是種通用寫法,冒號(hào)前為插件前綴,冒號(hào)后為插件目標(biāo)。例如,compiler:compile(maven-compiler-plugin的compile目標(biāo)),surefire:test(maven-surefire-plugin的test目標(biāo))
?內(nèi)置綁定?
Maven為了讓用戶幾乎不需要任何配置就可以構(gòu)建Maven項(xiàng)目,在核心為一些主要的生命周期階段綁定了插件的目標(biāo)。
- clean生命周期有pre-clean、clean、post-clean三個(gè)階段。其中clean與maven-clean-plugin:clean綁定。maven-clean-plugin僅有clean這一個(gè)目標(biāo),作用就是刪除項(xiàng)目的輸出目錄。
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>clean</role-hint>
<configuration>
<id>clean</id>
<phases>
<phase>pre-clean</phase>
<phase>clean</phase>
<phase>post-clean</phase>
</phases>
<default-phases>
<clean>
org.apache.maven.plugins:maven-clean-plugin:2.5:clean
</clean>
</default-phases>
</configuration>
</component>
- site生命周期有pre-site,site,post-site,site-deploy四個(gè)階段。site和maven-site-plugin:site綁定,用于生成項(xiàng)目站點(diǎn)。site-deploy和maven-site-plugin:deploy綁定,用于將項(xiàng)目站點(diǎn)部署到遠(yuǎn)程服務(wù)器上。
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>site</role-hint>
<configuration>
<id>site</id>
<phases>
<phase>pre-site</phase>
<phase>site</phase>
<phase>post-site</phase>
<phase>site-deploy</phase>
</phases>
<default-phases>
<site>
org.apache.maven.plugins:maven-site-plugin:3.3:site
</site>
<site-deploy>
org.apache.maven.plugins:maven-site-plugin:3.3:deploy
</site-deploy>
</default-phases>
</configuration>
</component>
- default生命周期,會(huì)相對(duì)上面兩種功能多一些,內(nèi)置的插件綁定以打包類型jar為例,有8個(gè)階段:
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>jar</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<phases>
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:resources
</process-resources>
<compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
</compile>
<process-test-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
</process-test-resources>
<test-compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
</test-compile>
<test>
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:2.4:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
</deploy>
</phases>
</lifecycle>
</lifecycles>
</configuration>
</component>
實(shí)際的階段有
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>default</role-hint>
<configuration>
<id>default</id>
<phases>
<phase>validate</phase>
<phase>initialize</phase>
<phase>generate-sources</phase>
<phase>process-sources</phase>
<phase>generate-resources</phase>
<phase>process-resources</phase>
<phase>compile</phase>
<phase>process-classes</phase>
<phase>generate-test-sources</phase>
<phase>process-test-sources</phase>
<phase>generate-test-resources</phase>
<phase>process-test-resources</phase>
<phase>test-compile</phase>
<phase>process-test-classes</phase>
<phase>test</phase>
<phase>prepare-package</phase>
<phase>package</phase>
<phase>pre-integration-test</phase>
<phase>integration-test</phase>
<phase>post-integration-test</phase>
<phase>verify</phase>
<phase>install</phase>
<phase>deploy</phase>
</phases>
</configuration>
</component>
其他的打包內(nèi)置插件綁定在components.xml可以查看到,同時(shí)可以參考Maven官方文檔
之前執(zhí)行過的mvn clean test
C:\Subversion\MavenPrj\helloMaven>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ hello-maven ---
[INFO] Deleting C:\Subversion\MavenPrj\helloMaven\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ hello-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Subversion\MavenPrj\helloMaven\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ hello-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Subversion\MavenPrj\helloMaven\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ hello-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Subversion\MavenPrj\helloMaven\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ hello-maven ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Subversion\MavenPrj\helloMaven\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ hello-maven ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.play.myMaven.HelloWorldTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.02 s - in com.play.myMaven.HelloWorldTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.969 s
[INFO] Finished at: 2018-06-05T19:52:48+08:00
[INFO] Final Memory: 16M/167M
[INFO] ------------------------------------------------------------------------
從輸出中可以看到Maven執(zhí)行插件目標(biāo)順序?yàn)椋?/p>
- maven-clean-plugin:clean
- maven-resources-plugin:resources
- maven-compiler-plugin:compile
- maven-resources-plugin:testResources
- maven-compiler-plugin:testCompile
- maven-surefire-plugin:test
對(duì)照上文的clean、default、site表格,可以看到在test及其之前的階段凡是綁定了內(nèi)置插件的階段均有相應(yīng)的插件執(zhí)行。
?自定義綁定?
除了Maven內(nèi)置綁定,Maven支持用戶自定義綁定,可以自己選擇將某個(gè)插件目標(biāo)綁定到生命周期的某個(gè)階段。
來(lái)舉個(gè)例子,創(chuàng)建項(xiàng)目的源碼jar包。內(nèi)置中并沒有涉及到這個(gè)任務(wù),需要我們自行配置。maven-source-plugin:jar-no-fork能夠?qū)㈨?xiàng)目的主代碼打包成jar文件,把這個(gè)插件綁定在default生命周期的verify階段上,在執(zhí)行完集成測(cè)試后創(chuàng)建源碼jar包。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
- 需要配置插件坐標(biāo)
- 配置插件執(zhí)行(每個(gè)聲明的任務(wù)都需要包裹在一個(gè)execution元素中),id元素為當(dāng)前POM唯一標(biāo)識(shí),phase元素指定階段,goal元素指定目標(biāo),還應(yīng)有個(gè)version元素這里我也不知道版本是什么就不寫version,讓Maven自動(dòng)尋找最新穩(wěn)定版(仍然建議在xml中聲明version版本),ctrl+鼠標(biāo)左鍵進(jìn)入jar-no-fork說(shuō)明:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
...
<mojo>
<goal>jar-no-fork</goal>
<description>This goal bundles all the sources into a jar archive.
This goal functions the same as the jar goal but does not fork the build
and is suitable for attaching to the build lifecycle.</description>
...
</mojo>
jar-no-fork目標(biāo)將所有的資源打包成一個(gè)jar歸檔文件。這個(gè)目標(biāo)與jar目標(biāo)的功能相同,但不派生構(gòu)建,適合附加到構(gòu)建生命周期。自定義插件綁定完成。運(yùn)行mvn verify
[INFO] --- maven-source-plugin:3.0.1:jar-no-fork (attach-sources) @ hello-maven ---
[INFO] Building jar: C:\Subversion\MavenPrj\helloMaven\target\hello-maven-1.0-SNAPSHOT-sources.jar
verify階段會(huì)執(zhí)行maven-source-plugin:jar-no-fork,并創(chuàng)建一個(gè)-sources.jar結(jié)尾的源碼文件包。
有時(shí)候不通過phase元素配置生命周期階段,插件目標(biāo)也能夠綁定到對(duì)應(yīng)的生命周期。因?yàn)椋泻芏嗖寮哪繕?biāo)在編寫時(shí)已經(jīng)定義了默認(rèn)綁定階段。可以使用maven-help-plugin查看插件詳細(xì)信息,了解插件目標(biāo)默認(rèn)綁定階段。運(yùn)行命令:mvn help:describe -Dplugin=org.apache.maven.plugins:maven-source-plugin:3.0.1 -Ddetail=true
source:test-jar-no-fork
Description: This goal bundles all the test sources into a jar archive.
This goal functions the same as the test-jar goal but does not fork the
build, and is suitable for attaching to the build lifecycle.
Implementation: org.apache.maven.plugins.source.TestSourceJarNoForkMojo
Language: java
Bound to phase: package
Bound to phase: package 默認(rèn)綁定的生命周期階段是package。若我們不指定phase參數(shù),該目標(biāo)會(huì)被綁定到 package 階段。
多個(gè)目標(biāo)被綁定到同一階段,根據(jù)插件聲明的先后順序決定目標(biāo)的執(zhí)行順序。
?插件配置?
1.命令行插件配置
在Maven命令中使用-D參數(shù),伴隨一個(gè)參數(shù)鍵=參數(shù)值的形式,來(lái)配置插件目標(biāo)的參數(shù)。(注意=兩側(cè)不要有空格)
eg:maven-surefire-plugin提供了一個(gè)maven.test.skip參數(shù),當(dāng)值為true就會(huì)跳過執(zhí)行測(cè)試:
執(zhí)行mvn install -Dmaven.test.skip=true
C:\Subversion\MavenPrj\helloMaven>mvn install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ hello-maven ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ hello-maven ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ hello-maven ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ hello-maven ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ hello-maven ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ hello-maven ---
[INFO] Building jar: C:\Subversion\MavenPrj\helloMaven\target\hello-maven-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) @ hello-maven ---
[INFO]
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ hello-maven ---
[INFO] Building jar: C:\Subversion\MavenPrj\helloMaven\target\hello-maven-1.0-SNAPSHOT-sources.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ hello-maven ---
[INFO] Installing C:\Subversion\MavenPrj\helloMaven\target\hello-maven-1.0-SNAPSHOT.jar to C:\Repository\m2repo\com\play\myMaven\hello-maven\1.0-SNAPSHOT\hello-maven-1.0-SNAPSHOT.jar
[INFO] Installing C:\Subversion\MavenPrj\helloMaven\pom.xml to C:\Repository\m2repo\com\play\myMaven\hello-maven\1.0-SNAPSHOT\hello-maven-1.0-SNAPSHOT.pom
[INFO] Installing C:\Subversion\MavenPrj\helloMaven\target\hello-maven-1.0-SNAPSHOT-sources.jar to C:\Repository\m2repo\com\play\myMaven\hello-maven\1.0-SNAPSHOT\hello-maven-1.0-SNAPSHOT-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
參數(shù)-D是Java自帶的,功能是通過命令行設(shè)置一個(gè)Java系統(tǒng)屬性,Maven簡(jiǎn)單地重用了該參數(shù),在準(zhǔn)備插件的時(shí)候檢查系統(tǒng)屬性,即實(shí)現(xiàn)了插件參數(shù)的配置。
resources:testResources 和compiler:testCompile 顯示Not copying test resources
surefire:surefire 顯示 Tests are skipped.
2.POM中插件全局配置
并不是所有插件都適合從命令行配置。有些參數(shù)的值從項(xiàng)目創(chuàng)建到項(xiàng)目發(fā)布都不會(huì)改變或者很少改變,這種情況在POM中一次性配置就比重復(fù)在命令行輸入要方便。
我們?cè)诼暶鞑寮臅r(shí)候,可以對(duì)插件進(jìn)行一個(gè)全局的配置,即基于該插件目標(biāo)的任務(wù),都會(huì)使用這些配置。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
無(wú)論綁定到哪個(gè)階段的javadoc:complie任務(wù),都會(huì)使用該配置,基于Java1.8進(jìn)行編譯。
3.POM中插件任務(wù)配置
同樣地,我們也可以對(duì)插件任務(wù)進(jìn)行配置。
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-docker-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<!--拷貝docker資源文件-->
<resource>
<directory>${project.basedir}/src/main/Docker</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
在prepare-package階段執(zhí)行copy-resources任務(wù)時(shí),輸出目錄為target,拷貝docker資源文件目錄為~/src/main/Docker
?獲取插件信息?
我們需要知道去哪里尋找合適的插件,找到后還需要知道該插件的配置點(diǎn)都有哪些。
1.在線插件信息
基本上所有主要的Maven插件都來(lái)自Apache和Codehaus。
所有官方插件能在這里下載:https://repo.maven.apache.org/maven2/和http://repository.codehaus.org/org/codehaus/mojo/
例如插件:maven-surefire-plugin,訪問http://maven.apache.org/plugins/maven-surefire-plugin
可以閱讀插件文檔中的介紹和實(shí)例。
查閱該插件的目標(biāo)。點(diǎn)擊Goal繼續(xù)查看目標(biāo)參數(shù)等信息。https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html
有Required Parameters、Optional Parameters、Parameter Details三個(gè)模塊,在Parameter Details中找到skip
skip:
Set this to "true" to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it using the "maven.test.skip" property,
because maven.test.skip disables both running the tests and compiling the tests. Consider using the skipTests parameter instead.
Type: boolean
Required: No
User Property: maven.test.skip
Default: false
2.通過maven-help-plugin描述插件
例如上文中的mvn help:describe -Dplugin=org.apache.maven.plugins:maven-source-plugin:3.0.1 -Ddetail=true
<plugin>
The Maven Plugin to describe. This must be specified in one of three ways:
plugin-prefix, i.e. 'help'
groupId:artifactId, i.e. 'org.apache.maven.plugins:maven-help-plugin'
Type: java.lang.String
Since: 2.0
Required: No
User Property: plugin
Alias: prefix
上述是help:describe的plugin參數(shù)的文檔描述,我們需要在plugin=后填入plugin-prefix插件前綴、groupId:artifactId、groupId:artifactId:version三種方式中的任意一種就OK了。
<detail>
This flag specifies that a detailed (verbose) list of goal (Mojo) information should be given.
Type: boolean
Since: 2.1
Required: No
User Property: detail
Default: false
上述是help:describe的detail參數(shù)的文檔描述,設(shè)置為true將會(huì)給出詳細(xì)的目標(biāo)信息。
我們來(lái)看下插件compiler的信息,運(yùn)行mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin
Name: Apache Maven Compiler Plugin
Description: The Compiler Plugin is used to compile the sources of your
project.
Group Id: org.apache.maven.plugins
Artifact Id: maven-compiler-plugin
Version: 3.7.0
Goal Prefix: compiler
This plugin has 3 goals:
compiler:compile
Description: Compiles application sources
compiler:help
Description: Display help information on maven-compiler-plugin.
Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display
parameter details.
compiler:testCompile
Description: Compiles application test sources.
For more information, run 'mvn help:describe [...] -Ddetail'
簡(jiǎn)化一下,用plugin-prefix來(lái)執(zhí)行。運(yùn)行mvn help:describe -Dplugin=compiler,結(jié)果同上述結(jié)果一致。
同理,目標(biāo)describe存在參數(shù)goal,那我們只看compiler中的compile任務(wù),就可以添加goal參數(shù)。運(yùn)行:mvn help:describe -Dplugin=compiler -Dgoal=compile即可
?從命令行調(diào)用插件?
執(zhí)行mvn -h命令
C:\Subversion\MavenPrj\helloMaven>mvn -h
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:...
另外
mvn help:describe -Dplugin=compile
mvn dependency:tree
等價(jià)于
mvn org.apache.maven.plugins:maven-help-plugin:describe -Dplugin=compiler
mvn org.apache.maven.plugins:maven-dependency-plugin:tree
?插件解析機(jī)制?*
1.插件倉(cāng)庫(kù)
Maven會(huì)區(qū)別對(duì)待依賴的遠(yuǎn)程倉(cāng)庫(kù)與插件的遠(yuǎn)程倉(cāng)庫(kù)
解壓一下$M2_HOME/lib/maven-model-builder-3.3.9.jar,進(jìn)入\org\apache\maven\model\,打開pom-4.0.0.xml,這個(gè)是所有Maven項(xiàng)目都會(huì)繼承的超級(jí)POM,里面有Maven內(nèi)置的pluginRepositories
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
對(duì)比內(nèi)置依賴的遠(yuǎn)程倉(cāng)庫(kù)repositories
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
原諒我沒看出來(lái)特別的地方......歡迎在評(píng)論區(qū)補(bǔ)充
2.插件的默認(rèn)groupId
在POM中配置插件的時(shí)候,如果該插件時(shí)Maven的官方插件(即如果其groupId是org.apache.maven.plugins),就可以忽略groupId配置。Maven在解析該插件的時(shí)候自動(dòng)補(bǔ)齊這個(gè)值。
3.解析插件版本
Maven在用戶沒有提供插件版本的情況下,會(huì)自動(dòng)解析插件版本。Maven在超級(jí)POM中為所有核心插件設(shè)定了版本。所有項(xiàng)目都繼承超級(jí)POM的配置。如果使用的某個(gè)插件版本沒有設(shè)定版本,同時(shí)又不屬于核心插件的范疇。Maven會(huì)去檢查所有倉(cāng)庫(kù)中可用的版本,然后做出選擇(最新的穩(wěn)定版本-release)。
4.解析插件前綴
插件前綴與groupId:artifactId是一一對(duì)應(yīng)的,這種匹配關(guān)系存儲(chǔ)在倉(cāng)庫(kù)元數(shù)據(jù)中。當(dāng)然我們也可以通過配置settings.xml讓Maven檢查其他pluginGroup上的插件倉(cāng)庫(kù)元數(shù)據(jù):
<settings>
<pluginGroups>
<pluginGroup>com.your.plugins</pluginGroup>
</pluginGroups>
</settings>
基于該配置,Maven就不僅僅會(huì)檢查org/apache/maven/plugins/maven-metadata.xml,還會(huì)檢查com/your/plugins/maven-metadata.xml
上述是org.apache.maven.plugins.groupId下插件倉(cāng)庫(kù)元數(shù)據(jù)中的片段。
可以看到maven-clean-plugin的前綴就是clean,maven-compiler-plugin的前綴就是compiler,maven-dependency-plugin的前綴就是dependency
當(dāng)Maven解析到dependency:tree時(shí),首先基于默認(rèn)的groupId歸并所有插件倉(cāng)庫(kù)的元數(shù)據(jù),即org/apache/maven/plugins/maven-metadata.xml,然后檢查歸并后的元數(shù)據(jù),找到對(duì)應(yīng)的artifactId;然后結(jié)合當(dāng)前元數(shù)據(jù)的groupId,解析得到version。如果org/apache/maven/plugins/maven-metadata.xml中沒有記錄該插件的前綴,接著檢查其他groupId下的元數(shù)據(jù),以及用戶自定義的插件組。所有元數(shù)據(jù)中都不包含該前綴,則報(bào)錯(cuò)。
《Maven實(shí)戰(zhàn)》學(xué)習(xí)筆記