Gradle 相当于 Maven 的“复制依赖"? [英] Gradle equivalent to Maven's "copy-dependencies"?

查看:57
本文介绍了Gradle 相当于 Maven 的“复制依赖"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Maven-land 中,任何时候我想简单地拉下特定 POM 文件的传递依赖项,我只需打开一个 shell,导航到 POM 所在的位置,然后运行:

In Maven-land, anytime I want to simply pull down the transitive dependencies for a particular POM file, I just open a shell, navigate to where the POM is located, and run:

mvn dependency:copy-dependencies

boom,Maven 在当前目录中创建一个 target/ 目录,并将所有可传递获取的 JAR 放置到该位置.

And boom, Maven creates a target/ directory inside the current one and places all the transitively-fetched JARs to that location.

我现在尝试切换到 Gradle,但 Gradle 似乎没有相同的功能.所以我问:Gradle 是否与 Maven 的 copy-dependencies 等效?如果是这样,有人可以提供一个例子吗?如果没有,其他开发者会认为这是对 Gradle 社区的一项有价值的贡献吗?

I am now trying to make the switch over to Gradle, but Gradle doesn't seem to have the same feature. So I ask: Does Gradle have an equivalent to Maven's copy-dependencies? If so, can someone provide an example? If not, would other devs find this to be a worthwhile contribution to the Gradle community?

推荐答案

gradle 中没有与 copy-dependencies 等效的东西,但这里有一个任务可以做到:

There's no equivalent of copy-dependencies in gradle but here's a task that does it:

apply plugin: 'java'

repositories {
   mavenCentral()
}

dependencies {
   compile 'com.google.inject:guice:4.0-beta5'
}

task copyDependencies(type: Copy) {
   from configurations.compile
   into 'dependencies'
}

做贡献值得吗?AS你可以看到这很容易做到,所以我不这么认为.

Is it worthwhile to do a contribution? AS You can see it's really easy to do, so I don't think so.

编辑

从 gradle 4+ 开始:

From gradle 4+ it will be:

task copyDependencies(type: Copy) {
  from configurations.default
  into 'dependencies'
}

这篇关于Gradle 相当于 Maven 的“复制依赖"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆