Maven?dependency?plugin使用心得總結(jié)
概要
Maven提供了很多的插件,具體有哪些插件,可以在官網(wǎng)上查到:
本篇博客主要是總結(jié)下對maven dependency插件的使用心得。
maven dependency插件的主要作用:
它屬于工具類的插件。它提供了操作構(gòu)件(artifact)的能力,可以從本地或者遠程倉庫 復制或者解壓特定構(gòu)件到指定位置。
目標(goals)
Dependency插件支持許多目標(goals),可以參考下面鏈接:
這里呢,主要介紹copy和copy-dependencies、unpack、get這幾個goals。
copy
通過在 pom.xml 文件中的插件配置處定義一系列構(gòu)件,可以做到復制、重命名、指定版本等操作。它可以解決本地倉庫或者項目中缺少某個構(gòu)件文件的問題,并把它們放到指定位置。
插件配置細節(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
作用:
從倉庫中復制項目依賴的構(gòu)件到指定位置。
插件配置細節(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)件,然后解壓它們到指定位置。
插件配置細節(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),包括可傳遞性。
插件配置細節(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提供了強大的插件功能,遇到任何不清楚地,可以去官網(wǎng)查找資料,然后本地嘗試
到此這篇關于Maven dependency plugin使用心得總結(jié)的文章就介紹到這了,更多相關Maven dependency plugin內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
mybatis-puls中的resultMap數(shù)據(jù)映射
這篇文章主要介紹了mybatis-puls中的resultMap數(shù)據(jù)映射,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
spring框架cacheAnnotation緩存注釋聲明解析
這篇文章主要介紹了spring框架中cacheAnnotation注釋聲明緩存解析示例有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-10-10
解決java讀取EXCEL數(shù)據(jù)變成科學計數(shù)法的問題
這篇文章主要介紹了解決java讀取EXCEL數(shù)據(jù)變成科學計數(shù)法的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04
MyBatis后端對數(shù)據(jù)庫進行增刪改查等操作實例
Mybatis是appach下開源的一款持久層框架,通過xml與java文件的緊密配合,避免了JDBC所帶來的一系列問題,下面這篇文章主要給大家介紹了關于MyBatis后端對數(shù)據(jù)庫進行增刪改查等操作的相關資料,需要的朋友可以參考下2022-08-08
解析Java?中for循環(huán)和foreach循環(huán)哪個更快
這篇文章主要介紹了Java中for循環(huán)和foreach循環(huán)哪個更快示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-09-09
Spring security密碼加密實現(xiàn)代碼實例
這篇文章主要介紹了Spring security密碼加密實現(xiàn)代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-04-04

