Gradle列表本地项目依赖项

编程入门 行业动态 更新时间:2024-10-16 02:27:53
本文介绍了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有几种检查依赖项的方法,但我认为其中没有一个过滤器将其限制为仅项目"依赖项.请参见 docs.gradle/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 docs.gradle/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 = configurationspile println " " * (3 * nesting) + project.name DomainObjectSet<ProjectDependency> projectDependencies = configuration.dependencies.withType ProjectDependency projectDependencies.forEach { showProjectDependencies(it.dependencyProject, nesting + 1) } }

更多推荐

Gradle列表本地项目依赖项

本文发布于:2023-11-09 04:38:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   列表   Gradle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!