MAVEN - 使用maven-dependency-plugin的应用场景是什么?

news/2024/7/8 1:49:22

简述

maven-dependency-plugin是MAVEN的一个插件。

作用

该插件主要用于管理项目中的依赖,使用该插件可以方便地查看、下载、复制和解压缩依赖,还支持生成依赖树和依赖报告。

功能

该插件有很多可用的GOAL,大部分与依赖构建、依赖分析和依赖解决相关,这些GOAL可以直接用MAVEN的命令操作。
官方定义的所有的GOAL:https://maven.apache.org/plugins/maven-dependency-plugin/index.html

在这里插入图片描述

常见的操作如下:
(1)mvn dependency:tree,显示该项目的依赖关系树;
在这里插入图片描述
(2)mvn dependency:analyze,分析项目依赖,确定哪些依赖是已使用已声明的,已使用未声明的,未使用已声明的?
在这里插入图片描述

(3)mvn dependency:copy,将配置在插件中的JAR包复制到指定位置;
copy的配置:https://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html
(4)mvn dependency:copy-dependencies,将项目POM文件中定义的所有依赖及其传递依赖复制到指定位置;
copy-dependencies的配置:https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html
(5)mvn dependency:unpack,将配置在插件中的JAR包复制到指定位置,并且将JAR包进行解压缩;
(6)mvn dependency:unpack-dependencies,将项目POM文件中定义的所有依赖及其传递依赖复制到指定位置,并且将JAR包进行解压缩;

应用场景

(1)某个特殊的JAR包,无法直接通过MAVEN依赖获取或者说MAVEN仓库内也不存在,那么如何将我们所需要的JAR包打入我们的生产JAR包中呢?使用:mvn dependency:copy 可以解决该问题
(2)某个特殊的JAR包内包含我们需要的文件,或者说我们如何将所需的文件从JAR包中提取出来并放入指定的位置?使用:mvn dependency:unpack 可以解决该问题

如何使用

第一步,在POM文件中添加如下内容:
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>3.2.0</version>
      <!--<executions> 标签中添加需要执行的操作,可以添加的操作如下: -->
      <executions>
        ...
      </executions>
    </plugin>
  </plugins>
</build>
第二步,根据需要添加相关操作:
  1. 将所有依赖包复制到 target/libs 目录下。
<execution>
  <id>copy-dependencies</id>
  <phase>package</phase>
  <goals>
    <goal>copy-dependencies</goal>
  </goals>
  <configuration>
    <outputDirectory>${project.build.directory}/libs</outputDirectory>
  </configuration>
</execution>
  1. 将所有依赖包解压到 target/classes/lib 目录下。
<execution>
  <id>unpack-dependencies</id>
  <phase>package</phase>
  <goals>
    <goal>unpack-dependencies</goal>
  </goals>
  <configuration>
    <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
  </configuration>
</execution>
  1. 将依赖列表输出到 target/dependency-report.txt 报告文件中。
<execution>
  <id>dependency-report</id>
  <phase>compile</phase>
  <goals>
    <goal>list</goal>
  </goals>
  <configuration>
    <outputFile>${project.build.directory}/dependency-report.txt</outputFile>
  </configuration>
</execution>
  1. 将junit-4.11.jar复制到${project.build.directory}/lib/lib1目录下,将slf4j-log4j12-1.7.7.jar复制到${project.build.directory}/lib/lib2目录下。
<execution>
	<id>copy</id>
	<phase>package</phase>
	<goals>
		<goal>copy</goal>
	</goals>
	<configuration>
		<artifactItems>
			<artifactItem>
				<groupId>junit</groupId>
				<artifactId>junit</artifactId>
				<version>4.11</version>
				<outputDirectory>${project.build.directory}/lib/lib1</outputDirectory>
			</artifactItem>
			<artifactItem>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-log4j12</artifactId>
				<version>1.7.7</version>
				<outputDirectory>${project.build.directory}/lib/lib2</outputDirectory>
			</artifactItem>
		</artifactItems>
	</configuration>
</execution>
  1. 将dubbo-2.8.4.jar文件中META-INF/assembly/bin下的所有文件复制到${project.build.directory}/dubbo目录中。
<execution>
	<id>unpack</id>
	<phase>package</phase>
	<goals>
		<goal>unpack</goal>
	</goals>
	<configuration>
		<artifactItems>
			<artifactItem>
				<groupId>com.alibaba</groupId>
				<artifactId>dubbo</artifactId>
				<version>2.8.4</version>
				<outputDirectory>${project.build.directory}/dubbo</outputDirectory>
				<includes>META-INF/assembly/bin\**</includes>
			</artifactItem>
		</artifactItems>
	</configuration>
</execution>

http://lihuaxi.xjx100.cn/news/1242996.html

相关文章

arcpy批量提取面状水系中间线

由于面状水系可能存在多条中间线&#xff0c;因此批量提取时需要使用 ArcGIS 中的 Feature To Line 工具结合 Python 循环和游标来完成。 以下是代码&#xff1a; import arcpy import os # 设置输入输出路径和文件名 input_folder r"C:\data\river_polygons" out…

阿里云弹性公网EIP收费价格表

阿里云弹性公网EIP怎么收费&#xff1f;EIP地域不同价格不同&#xff0c;EIP计费模式分为包年包月和按量付费&#xff0c;弹性公网IP可以按带宽收费也可以按使用流量收费&#xff0c;阿里云百科分享阿里云弹性公网IP不同地域、不同计费模式、按带宽和按使用流量详细收费价格表&…

005、体系结构之TiKV_Raft日志

Raft日志 1、Raft与Multi Raft2、Raft 日志复制2.1、复制流程总览2.2、Propose2.3、Append2.3、Replicate(Append)2.4 Committed2.4 Apply 3、Raft Leader 选举3.1、原理3.2、节点故障Leader&#xff08;主副本&#xff09;选举⽇志复制 1、Raft与Multi Raft 一个region的大小是…

Linux系统的tty架构及UART驱动详解

​一、模块硬件学习 1.1. Uart介绍 通用异步收发传输器&#xff08;Universal Asynchronous Receiver/Transmitter)&#xff0c;通常称为UART&#xff0c;是一种异步收发传输器&#xff0c;是电脑硬件的一部分。它将要传输的资料在串行通信与并行通信之间加以转换。 作为把并…

Python爬虫之基础知识

爬虫基础知识 一、爬虫的概念 模拟浏览器&#xff0c;发送请求&#xff0c;获取响应 网络爬虫&#xff08;又被称为网页蜘蛛&#xff0c;网络机器人&#xff09;就是模拟客户端(主要指浏览器)发送网络请求&#xff0c;接收请求响应&#xff0c;一种按照一定的规则&#xff0c;…

IMX6ULL裸机篇之SPI实验-SPI主控代码实现

一. SPI 实验 SPI实验&#xff1a;学习如何使用 I.MX6U 的 SPI 接口来驱动 ICM-20608&#xff0c;读取 ICM-20608 的六轴数据。 本文学习 SPI主控芯片的代码编写。其中&#xff0c;包括SPI工作模式设置&#xff0c;主从模式设置&#xff0c;时钟配置等实现。 二. SPI 主控芯…

Servlet+jsp+Layui图书管理系统

项目介绍 介绍 使用到了jsp&#xff0c;servlet&#xff0c;Mysql&#xff0c;Java&#xff0c;layui。 大致功能 关于用户&#xff1a; 登录&#xff0c;申请注册&#xff0c;查看搜索图书&#xff0c;查看有关用户的借阅记录&#xff0c;丢失记录&#xff0c;预借记录。对…

华为OD机试 JavaScript 实现【扑克牌大小】【牛客练习题 HJ88】,附详细解题思路

一、题目描述 扑克牌游戏大家应该都比较熟悉了&#xff0c;一副牌由54张组成&#xff0c;含3~A、2各4张&#xff0c;小王1张&#xff0c;大王1张。牌面从小到大用如下字符和字符串表示&#xff08;其中&#xff0c;小写joker表示小王&#xff0c;大写JOKER表示大王&#xff09…