简体   繁体   English

识别已在gradle中调用的项目列表

[英]Identifying the list of projects that have been invoked in gradle

I have a settings plugin that is multi-project aware. 我有一个支持多项目的设置插件。 It currently applies itself to every project identified in settings.gradle . 当前,它将自身应用于settings.gradle标识的每个项目。 However, this is a problem because each subproject doesn't have the same configuration, and I control some plugin behavior through project properties set on the command-line via -P . 但是,这是一个问题,因为每个子项目的配置都不相同,并且我通过-P在命令行上设置的项目属性来控制某些插件行为。

The problem is that this fails on projects that don't have the configuration necessary to use that property, and I know of know way to apply a property to a specific subproject via the command-line. 问题是,在没有使用该属性所需的配置的项目上,该操作将失败,并且我知道通过命令行将属性应用于特定子项目的已知方法。

Instead of iterating over settings.gradle.allprojects , is there a way to know what projects have actually been included as part of the build? 而不是遍历settings.gradle.allprojects ,有没有办法知道哪些项目实际上已包含在构建中? For example when I do: 例如,当我这样做时:

gradle :subproject-name:build :other-subproject-name:build -PsomeProperty

I would like to know that only subproject-name and other-subproject-name were called so that I can apply the settings plugin to only those projects. 我想知道仅调用了subproject-nameother-subproject-name ,以便我可以将设置插件仅应用于那些项目。

Or is there a way to "scope" project properties somehow, to only a particular project? 还是有一种方法可以某种方式将“项目”属性“范围”到仅特定项目?

... is there a way to know what projects have actually been included as part of the build? ...有没有办法知道哪些项目实际上已包含在构建中?

This is a misconception. 这是一个误解。 All projects are part of the build when settings.gradle includes them, and they'll all get configured so they have an associated Project . settings.gradle包含所有项目时,所有项目都是构建的一部分,并且都将对其​​进行配置,以便它们具有关联的Project

What you're ultimately looking for is, given the tasks that will execute, what are the subprojects who own those tasks? 您最终要寻找的是,给定将要执行的任务,拥有这些任务的子项目是什么? To do that, you can grab Gradle's task graph, and for all of the tasks that will execute, find the project that owns each task. 为此,您可以获取Gradle的任务图,对于将要执行的所有任务,找到拥有每个任务的项目。

gradle.taskGraph.whenReady { graph ->
    def projects = graph.allTasks.collect { it.project }.toSet()
    projects.each {
        println "Project is being used in this build: " + it
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM