Maven?dependency?plugin使用心得總結(jié)
概要
Maven提供了很多的插件,具體有哪些插件,可以在官網(wǎng)上查到:
本篇博客主要是總結(jié)下對maven dependency插件的使用心得。
maven dependency插件的主要作用:
它屬于工具類的插件。它提供了操作構(gòu)件(artifact)的能力,可以從本地或者遠(yuǎn)程倉庫 復(fù)制或者解壓特定構(gòu)件到指定位置。
目標(biāo)(goals)
Dependency插件支持許多目標(biāo)(goals),可以參考下面鏈接:
這里呢,主要介紹copy和copy-dependencies、unpack、get這幾個goals。
copy
通過在 pom.xml 文件中的插件配置處定義一系列構(gòu)件,可以做到復(fù)制、重命名、指定版本等操作。它可以解決本地倉庫或者項目中缺少某個構(gòu)件文件的問題,并把它們放到指定位置。
插件配置細(xì)節(jié)可以看官網(wǎng)介紹在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> <!-- other configurations here --> </configuration> </execution> </executions> </plugin> </plugins> </build> [...] </project>
配置完,可以通過如下命令行執(zhí)行:
mvn dependency:copy
copy-dependencies
作用:
從倉庫中復(fù)制項目依賴的構(gòu)件到指定位置。
插件配置細(xì)節(jié)可以看官網(wǎng)介紹在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>
配置完,可以通過如下命令行執(zhí)行:
mvn dependency:copy-dependencies
unpack
作用:
從倉庫中抓取一系列構(gòu)件,然后解壓它們到指定位置。
插件配置細(xì)節(jié)可以看官網(wǎng)介紹在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>
配置完,可以通過如下命令行執(zhí)行:
mvn dependency:unpack
get
作用:
從指定的倉庫解析單個構(gòu)件(artifact),包括可傳遞性。
插件配置細(xì)節(jié)可以看官網(wǎng)介紹
操作命令如下:舉例獲得spring-core
mvn dependency:get -DgroupId=org.springframework -DartifactId=spring-core -Dversion=5.1.5.RELEASE transitive=true
其中,transitive=true 代表同時還要抓取該構(gòu)件的依賴構(gòu)件。
總結(jié)
maven提供了強(qiáng)大的插件功能,遇到任何不清楚地,可以去官網(wǎng)查找資料,然后本地嘗試
到此這篇關(guān)于Maven dependency plugin使用心得總結(jié)的文章就介紹到這了,更多相關(guān)Maven dependency plugin內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java Bean與json對象間的轉(zhuǎn)換實例講解
在本篇文章里小編給大家整理的是關(guān)于java Bean與json間的轉(zhuǎn)換的實例內(nèi)容,有需要的朋友們吧可以學(xué)習(xí)參考下。2020-01-01SpringCloud微服務(wù)續(xù)約實現(xiàn)源碼分析詳解
這篇文章主要介紹了SpringCloud微服務(wù)續(xù)約實現(xiàn)源碼分析,服務(wù)續(xù)期和服務(wù)注冊非常相似,服務(wù)注冊在Eureka?Client程序啟動之后開啟,并同時開啟服務(wù)續(xù)期的定時任務(wù)2022-11-11