Gradle列表本地项目依赖项 [英] Gradle list local project dependencies

查看:71
本文介绍了Gradle列表本地项目依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下项目结构:

root
- A
- B
    - B1
    - B2
- C

B1取决于B2和A.B2也取决于A和C.所有这些项目还具有从外部资源库中下载的外部依赖项.

with B1 depending on B2 and A. B2 also depends on A and on C. All of these projects have also external dependencies that are downloaded from a central repository.

是否有gradle任务来获取所有本地依赖项(可传递)?我想要某种

Is there a gradle task to get all local dependencies (transitive)? I want to some kind of

B1
- A
- B2
  - A
  - C

最好是平坦的,没有重复.该项目本身也可以省略,这并不重要.注意:没有显示来自中央存储库的依赖项

preferably flat and without duplicates. The project itself might be omitted as well, that is not important. Note: No dependencies from central repositories are shown

这样的任务存在吗?

推荐答案

gradle有几种检查依赖项的方法,但我认为其中没有一个过滤器将其限制为仅项目"依赖项.请参见 https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

gradle has several ways of inspecting dependencies, but I don't think any of it has a filter that restricts it to only "project" dependencies. See https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

还请注意,项目具有不同的依赖项配置,其中每个配置都有其自己的依赖项集.

Also note that a project has different dependency configurations where each configuration has its own set of dependencies.

因此,您需要谈谈有关显示项目的所有编译"依赖项的情况.

So you need to talk for example about showing all "compile" dependencies of a project.

但是gradle的一大优点是它可以轻松地用groovy编写脚本.

However one of the big advantages of gradle is that it is easily scriptable with groovy.

此快速草稿对我有用,以显示编译"配置中的所有依赖项.只需将其添加到根项目中,然后调用"gradlew projectDependencies".这已经在一个示例项目中进行了测试(换句话说,未经测试"),并且不是很灵活(编译"配置是硬编码的).但是,我尝试通过使用显式类型和多行代码使其易于理解,以便您可以对其进行扩展:

This quick draft works for me to show all dependencies in "compile" configuration. Just add it to the root project and invoke "gradlew projectDependencies". This has been tested in exactly one example project (in other words "mostly untested") and is not very flexible ("compile" configuration is hardcoded). However I tried to make it understandable by using explicit types and multiple lines, so that you can extend it:

task projectDependencies {
    doLast {
        showProjectDependencies(rootProject, 0)
    }
}

def showProjectDependencies(Project project, int nesting) {
    ConfigurationContainer configurations = project.configurations
    Configuration configuration = configurations.compile
    println " " * (3 * nesting) + project.name
    DomainObjectSet<ProjectDependency> projectDependencies = configuration.dependencies.withType ProjectDependency
    projectDependencies.forEach {
        showProjectDependencies(it.dependencyProject, nesting + 1)
    }
}

这篇关于Gradle列表本地项目依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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