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

