生活随笔
收集整理的这篇文章主要介绍了
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使用的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。