如何收集 Gradle 7 中的所有依赖项?

发布于 2025-01-14 04:44:53 字数 729 浏览 2 评论 0原文

在 Gradle 6 中,我使用以下代码片段收集项目中的所有依赖项(使用 project.configurations.runtime)并将它们复制到文件夹 "$buildDir/libs"

tasks.register<Copy>("copyDependenciesToLib") {
    into("$buildDir/libs")
    from(project.configurations.runtime)
    doLast {
        println("copyDependenciesToLib:\n  ${project.configurations.runtime.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
    }
}

我目前正在迁移到 Gradle 7,IntelliJ 告诉我 runtime 无法解析,似乎它已从 configuration 中删除? 你能为我指明在 Gradle 7 中重现上述脚本行为的正确方向吗?

未解析的参考

With Gradle 6 I used following snippet to collect all dependencies in my project (using project.configurations.runtime) and copy them to a folder "$buildDir/libs".

tasks.register<Copy>("copyDependenciesToLib") {
    into("$buildDir/libs")
    from(project.configurations.runtime)
    doLast {
        println("copyDependenciesToLib:\n  ${project.configurations.runtime.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
    }
}

I am currently migrating to Gradle 7, and IntelliJ tells me that runtime cannot be resolved, it seems that it has been removed from configuration?
Can you point me in the right direction to reproduce the behavior of the above script in Gradle 7?

Unresolved reference

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧故 2025-01-21 04:44:53

我自己刚刚找到了答案。

此处提出了类似的问题。

Gradle 已在 Gradle 7 中删除了运行时配置

。可以使用 运行时类路径

我们的 copy 任务现在如下所示:

tasks.register<Copy>("copyDependenciesToLib") {
    into("$buildDir/libs")
    from(project.configurations.runtimeClasspath)
    doLast {
        println("copyDependenciesToLib:\n  ${project.configurations.runtimeClasspath.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
    }
}

I just found the answer myself.

A similar question has been asked here.

Gradle has removed the runtime configuration in Gradle 7.

Instead, one can use runtimeClasspath.

Our copy task now looks the following:

tasks.register<Copy>("copyDependenciesToLib") {
    into("$buildDir/libs")
    from(project.configurations.runtimeClasspath)
    doLast {
        println("copyDependenciesToLib:\n  ${project.configurations.runtimeClasspath.get().files.joinToString("\n  ") { it.absolutePath }}\n  ->\n  $buildDir/libs")
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文