maven下载指定jar包到本地指定目录

2023-05-11 09:11:44 浏览数 (2)

  1. 创建pom.xml
代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.sample</groupId>
    <artifactId>download-jar</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <dependencies>
        <!-- 要下载的项目 -->
        <dependency>
            <groupId>org.sample</groupId>
            <artifactId>app</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <!-- 不要下载间接依赖的包 -->
                    <excludeTransitive>true</excludeTransitive> 
                    <!-- 复制的包去掉版本信息 -->
                    <stripVersion>true</stripVersion>
                    <!-- 复制到当前路径下的target文件夹里 -->
                    <outputDirectory>./target</outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  1. 执行命令
代码语言:javascript复制
mvn dependency:copy-dependencies

注:如果excludeTransitive没有配置为true,则会将所有间接依赖的包都下载下来

0 人点赞