生活随笔
收集整理的這篇文章主要介紹了
Maven dependency plugin使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
- 概要
- 目標(goals)
- copy
- copy-dependencies
- unpack
- get
- 總結
概要
Maven提供了很多的插件,具體有哪些插件,可以在官網上查到:
http://maven.apache.org/plugins/index.html
本篇博客主要是總結下對maven dependency插件的使用心得。
maven dependency插件的主要作用:
它屬于工具類的插件。它提供了操作構件(artifact)的能力,可以從本地或者遠程倉庫 復制或者解壓特定構件到指定位置。
目標(goals)
Dependency插件支持許多目標(goals),可以參考下面鏈接:
http://maven.apache.org/plugins/maven-dependency-plugin/
這里呢,主要介紹copy和copy-dependencies、unpack、get這幾個goals。
copy
通過在 pom.xml 文件中的插件配置處定義一系列構件,可以做到復制、重命名、指定版本等操作。它可以解決本地倉庫或者項目中缺少某個構件文件的問題,并把它們放到指定位置。
插件配置細節可以看官網介紹
在pom.xml中的配置參考如下:
<project>[...]
<build><plugins><plugin><groupId>org.apache.maven.plugins
</groupId><artifactId>maven-dependency-plugin
</artifactId><version>3.1.1
</version><executions><execution><id>copy
</id><phase>package
</phase><goals><goal>copy
</goal></goals><configuration><artifactItems><artifactItem><groupId>[ groupId ]
</groupId><artifactId>[ artifactId ]
</artifactId><version>[ version ]
</version><type>[ packaging ]
</type><classifier> [classifier - optional]
</classifier><overWrite>[ true or false ]
</overWrite><outputDirectory>[ output directory ]
</outputDirectory><destFileName>[ filename ]
</destFileName></artifactItem></artifactItems></configuration></execution></executions></plugin></plugins></build>[...]
</project>
配置完,可以通過如下命令行執行:
mvn dependency:copy
copy-dependencies
作用:
從倉庫中復制項目依賴的構件到指定位置。
插件配置細節可以看官網介紹
在pom.xml中的配置參考如下:
<project>[...]
<build><plugins><plugin><groupId>org.apache.maven.plugins
</groupId><artifactId>maven-dependency-plugin
</artifactId><version>3.1.1
</version><executions><execution><id>copy-dependencies
</id><phase>package
</phase><goals><goal>copy-dependencies
</goal></goals><configuration><outputDirectory>${project.build.directory}/alternateLocation
</outputDirectory><overWriteReleases>false
</overWriteReleases><overWriteSnapshots>false
</overWriteSnapshots><overWriteIfNewer>true
</overWriteIfNewer></configuration></execution></executions></plugin></plugins></build>[...]
</project>
配置完,可以通過如下命令行執行:
mvn dependency:copy-dependencies
unpack
作用:
從倉庫中抓取一系列構件,然后解壓它們到指定位置。
插件配置細節可以看官網介紹
在pom.xml中的配置參考如下:
<project>[...]
<build><plugins><plugin><groupId>org.apache.maven.plugins
</groupId><artifactId>maven-dependency-plugin
</artifactId><version>3.1.1
</version><executions><execution><id>unpack
</id><phase>package
</phase><goals><goal>unpack
</goal></goals><configuration><artifactItems><artifactItem><groupId>junit
</groupId><artifactId>junit
</artifactId><version>3.8.1
</version><type>jar
</type><overWrite>false
</overWrite><outputDirectory>${project.build.directory}/alternateLocation
</outputDirectory><destFileName>optional-new-name.jar
</destFileName><includes>**/*.class,**/*.xml
</includes><excludes>**/*test.class
</excludes></artifactItem></artifactItems><includes>**/*.java
</includes><excludes>**/*.properties
</excludes><outputDirectory>${project.build.directory}/wars
</outputDirectory><overWriteReleases>false
</overWriteReleases><overWriteSnapshots>true
</overWriteSnapshots></configuration></execution></executions></plugin></plugins></build>[...]
</project>
配置完,可以通過如下命令行執行:
mvn dependency:unpack
get
作用:
從指定的倉庫解析單個構件(artifact),包括可傳遞性。
插件配置細節可以看官網介紹
操作命令如下:舉例獲得spring-core
mvn dependency:get -DgroupId=org.springframework -DartifactId=spring-core -Dversion=5.1.5.RELEASE transitive=true
其中,transitive=true 代表同時還要抓取該構件的依賴構件。
總結
maven提供了強大的插件功能,遇到任何不清楚地,可以去官網查找資料,然后本地嘗試
總結
以上是生活随笔為你收集整理的Maven dependency plugin使用的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。