You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Maven Dependency Plugin的copy功能无法正常工作

问题分析与修复方案

我一眼就瞅出问题所在啦——你在maven-dependency-plugin的copy-dependencies执行块里,把目标(goal)写错了!

你当前配置里用的是<goal>compile</goal>,但maven-dependency-plugin根本没有这个goal,要实现复制依赖到指定目录的功能,正确的goal必须是copy-dependencies才行。

修正后的完整配置示例

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>compile</phase>
            <goals>
                <!-- 这里替换成正确的goal -->
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <!-- 可选:根据需求添加额外配置,比如只复制运行时依赖 -->
                <!-- <includeScope>runtime</includeScope> -->
                <!-- <excludeTransitive>false</excludeTransitive> -->
            </configuration>
        </execution>
    </executions>
</plugin>

额外小提示

  • 如果你想在打包环节自动执行依赖复制,可以把<phase>改成package,这样执行mvn package时就会自动把依赖拷贝到指定目录。
  • 要是只想临时手动触发这个操作,也可以直接在命令行跑:mvn dependency:copy-dependencies,不用依赖pom里的execution配置。

内容的提问来源于stack exchange,提问作者Dmitriy Ryabin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:49:08