【01】Maven依赖插件之maven-dependency-plugin
一、插件目标(goal)
1、analyze:分析项目依赖,确定哪些是已使用已声明的,哪些是已使用未声明的,哪些是未使用已声明的
2、analyze-dep-mgt:分析项目依赖,列出已解析的依赖项与dependencyManagement中定义的依赖项不匹配的部分
3、analyze-report:生成项目报告
4、analyze-duplicate:分析pom.xml中的<dependencies/>和<dependencyManagement/>标记,确定重复声明的依赖项
5、build-classpath:告诉Maven以类路径格式从本地存储库输出依赖项的路径
6、copy:将配置在插件中的jar包复制到指定位置
7、copy-dependencies:将项目pom文件中定义的所有依赖及其传递依赖复制到指定位置
8、display-ancestors:显示项目所有祖先pom
8、get:从远程库中解析出一个构件
9、go-offline:让maven解决该项目所依赖的所有内容,以准备脱机
10、list:resolve的别名,列出项目的所有依赖项
11、list-repositores:显示项目所有依赖项目,然后列出使用的存储库
12、properties:包含文件系统上的工件的每个项目依赖项设置一个属性
13、purge-local-repository:清除本地存储库中的依赖
14、resolve:告诉Maven解析所有依赖项并显示版本。JAVA 9注意: 在使用Java 9运行时将显示模块名称。
15、resolve-plugins:告诉Maven解决插件及其依赖项
16、sources:告诉Maven解析所有依赖项及其源附件、并显示版本
17、tree:显示该项目的依赖关系树
18、unpack:解压缩
19、unpack-dependencies:与copy-dependencies功能一致,只是会解压
二、使用举例
1、复制特定的构件(jar包)
<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> </execution> </executions> <configuration> <artifactItems> <artifactItem> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <type>jar</type> <overWrite>false</overWrite> <!-- jar包的存放位置 --> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <!--给jar包取别名 --> <destFileName>optional-new-name.jar</destFileName> </artifactItem> </artifactItems> <outputDirectory>${project.build.directory}/wars</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> </configuration> </plugin>
2、复制所有的依赖jar包到指定位置
<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> <!-- jar包存放位置 --> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin>
若是以命令行执行,则改为以下配置:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.1</version> <configuration> <artifactItems> <artifactItem> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <type>jar</type> <overWrite>false</overWrite> <outputDirectory>target/sources</outputDirectory> <destFileName>34.jar</destFileName> <includes>**/*.class,**/*.xml</includes> <excludes>**/*test.class</excludes> </artifactItem> </artifactItems> <!-- other configurations here --> </configuration> </plugin>
3、解压所有依赖项
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.1</version> <executions> <execution> <id>unpack-dependencies</id> <phase>package</phase> <goals> <goal>unpack-dependencies</goal> </goals> <configuration> <includes>**/*.class</includes> <excludes>**/*.properties</excludes> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>true</overWriteSnapshots> </configuration> </execution> </executions> </plugin>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!