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

Gradle 8.4升级后copyDependencies任务失效问题求助

Gradle 8.4 升级后 copyDependencies 任务修复方案

核心问题排查与修复步骤

1. 修正任务定义语法

你原来的任务嵌套写法不符合 Gradle 标准语法,在 8.x 版本中会导致任务无法正确注册。直接调整为标准任务声明方式:

task copyDependencies(type: Copy) {
    from configurations.runtimeClasspath
    into '../out/bin/lib'
}

注意:旧版的configurations.default在 Gradle 8.x 中已被废弃,替换为configurations.runtimeClasspath可以确保获取到项目运行时所需的全部依赖。

2. 规范 finalizedBy 配置

原数组赋值写法虽兼容部分版本,但 8.x 中更稳妥的写法是直接传入任务对象:

jar.finalizedBy(copyDependencies)

3. 确保依赖解析完成后执行任务

若任务仍不触发,可添加显式依赖保证配置解析完成后再执行复制:

copyDependencies.dependsOn(configurations.runtimeClasspath)

同时执行./gradlew tasks --all命令,确认copyDependencies已出现在任务列表中,验证任务是否成功注册。

4. 兜底处理目录权限与存在性

目标目录不存在或无权限也会导致任务失效,可在任务中自动创建目录:

task copyDependencies(type: Copy) {
    into '../out/bin/lib'
    from configurations.runtimeClasspath
    doFirst {
        file(destinationDir).mkdirs()
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 10:16:06