获取gradle模块的名称,以及它所依赖的任何其他模块的名称
假设我有一个多模块的gradle项目,有两个gradle模块,获取gradle模块的名称,以及它所依赖的任何其他模块的名称,gradle,android-gradle-plugin,gradle-plugin,Gradle,Android Gradle Plugin,Gradle Plugin,假设我有一个多模块的gradle项目,有两个gradle模块,:a和:B . ├── :A │ └── build.gradle ├── :B │ └── build.gradle ├── build.gradle (plugin applied here) └── settings.gradle :A没有依赖项 :B依赖于:a 我想得到以下信息 项目中每个模块的名称列表::a,:B 每个模块依赖的模块名称列表。对于:A,这将是一个空列表,而对于:B则是列表(“:A”)(
:a
和:B
.
├── :A
│ └── build.gradle
├── :B
│ └── build.gradle
├── build.gradle (plugin applied here)
└── settings.gradle
没有依赖项:A
依赖于:B
:a
- 项目中每个模块的名称列表:
,:a
:B
- 每个模块依赖的模块名称列表。对于
,这将是一个空列表,而对于:A
则是:B
(单元素列表)列表(“:A”)
此用例用于生成多模块项目中每个模块的连接方式的可视化表示这里有一个片段,用于遍历每个
配置
,并从中获取项目依赖关系
类型。它使用在评估所有项目后执行的。搞清楚过渡词或保持谁依赖于谁的观念是没有任何作用的,但这有希望给你一个起点,让你知道如何实现你想要的
gradle.projectsevaluate{
println('已加载的项目')
println('*'*15)
allprojects.forEach{proj->
最终列表projectDependencies=proj.configurations.collectMany{Configuration-Configuration->
配置.allDependencies
}.findAll{依赖关系->
ProjectDependency的依赖实例
}.收集{
它作为项目依赖关系
}.unique().collect()
println(“项目${proj.name}”)
println(projectDependencies.collect{“${it.name}->${it.dependencyProject.path}}}.join(System.lineSeparator()))
println()
}
}
我在存储库中试用了它,得到了以下输出:
Projects loaded
***************
Project junit5
Project documentation
junit-jupiter-api -> :junit-jupiter-api
junit-jupiter-params -> :junit-jupiter-params
junit-platform-runner -> :junit-platform-runner
junit-platform-launcher -> :junit-platform-launcher
junit-platform-console -> :junit-platform-console
junit-vintage-engine -> :junit-vintage-engine
junit-jupiter-engine -> :junit-jupiter-engine
Project junit-jupiter-api
junit-platform-commons -> :junit-platform-commons
Project junit-jupiter-engine
junit-platform-engine -> :junit-platform-engine
junit-jupiter-api -> :junit-jupiter-api
junit-platform-launcher -> :junit-platform-launcher
junit-platform-runner -> :junit-platform-runner
junit-platform-engine -> :junit-platform-engine
junit-platform-console -> :junit-platform-console
Project junit-jupiter-migrationsupport
junit-jupiter-api -> :junit-jupiter-api
junit-jupiter-engine -> :junit-jupiter-engine
junit-platform-launcher -> :junit-platform-launcher
junit-platform-runner -> :junit-platform-runner
junit-platform-engine -> :junit-platform-engine
junit-platform-console -> :junit-platform-console
Project junit-jupiter-params
junit-jupiter-api -> :junit-jupiter-api
junit-platform-engine -> :junit-platform-engine
junit-jupiter-engine -> :junit-jupiter-engine
junit-platform-launcher -> :junit-platform-launcher
junit-platform-runner -> :junit-platform-runner
junit-platform-console -> :junit-platform-console
Project junit-platform-commons
Project junit-platform-console
junit-platform-launcher -> :junit-platform-launcher
Project junit-platform-console-standalone
junit-platform-console -> :junit-platform-console
junit-jupiter-engine -> :junit-jupiter-engine
junit-jupiter-params -> :junit-jupiter-params
junit-vintage-engine -> :junit-vintage-engine
junit-jupiter-api -> :junit-jupiter-api
junit-jupiter-params -> :junit-jupiter-params
Project junit-platform-engine
junit-platform-commons -> :junit-platform-commons
Project junit-platform-gradle-plugin
junit-platform-console -> :junit-platform-console
junit-platform-launcher -> :junit-platform-launcher
junit-jupiter-api -> :junit-jupiter-api
junit-platform-console -> :junit-platform-console
junit-jupiter-engine -> :junit-jupiter-engine
Project junit-platform-launcher
junit-platform-engine -> :junit-platform-engine
Project junit-platform-runner
junit-platform-launcher -> :junit-platform-launcher
junit-platform-suite-api -> :junit-platform-suite-api
Project junit-platform-suite-api
junit-platform-commons -> :junit-platform-commons
Project junit-platform-surefire-provider
junit-platform-launcher -> :junit-platform-launcher
junit-jupiter-api -> :junit-jupiter-api
junit-platform-runner -> :junit-platform-runner
junit-jupiter-engine -> :junit-jupiter-engine
junit-platform-console -> :junit-platform-console
Project junit-vintage-engine
junit-platform-engine -> :junit-platform-engine
junit-platform-launcher -> :junit-platform-launcher
junit-jupiter-api -> :junit-jupiter-api
junit-platform-runner -> :junit-platform-runner
junit-platform-engine -> :junit-platform-engine
junit-platform-console -> :junit-platform-console
junit-jupiter-engine -> :junit-jupiter-engine
Project platform-tests
junit-platform-commons -> :junit-platform-commons
junit-platform-console -> :junit-platform-console
junit-platform-engine -> :junit-platform-engine
junit-platform-launcher -> :junit-platform-launcher
junit-jupiter-api -> :junit-jupiter-api
junit-jupiter-params -> :junit-jupiter-params
junit-platform-runner -> :junit-platform-runner
junit-platform-engine -> :junit-platform-engine
junit-jupiter-engine -> :junit-jupiter-engine
junit-vintage-engine -> :junit-vintage-engine
junit-jupiter-migrationsupport -> :junit-jupiter-migrationsupport
junit-platform-gradle-plugin -> :junit-platform-gradle-plugin
junit-platform-surefire-provider -> :junit-platform-surefire-provider
你是说
A
和B
以及多模块项目中的项目还是多模块项目本身?@Opal多模块项目(标准安卓项目设置)我相信你能简单地勾勒一下结构以及相关的*.gradle
文件吗?简单的ASCII树就足够了。添加,请参阅edit@Opal哈哈,好的捕获-修复!这很好,但是请记住,这段代码中使用了gradl的内部API。@Opal我认为我没有使用任何内部API(据我所知)。你说得对!我认为ProjectDependency
来自内部API。酷!:)我的项目的依赖项(Android)是DefaultDependencySet
,而不是ProjectDependency
。隐马尔可夫模型。。