I'm working on a multi-project gradle configuration.
In the root project, there is a Plugin that scans all sub-projects to looking for "NativeComponents", then creates a generic task with dependencies for all native component's build-tasks found.
The problem is when I set the dependencies (to component's build-tasks) of the generic task. If I try to set the dependencies when i create the generic task (during root project's evaluation), it show me the error:
Task with path ':CppProj:cppComponentExecutable' not found in root project 'RootProject'.
If I try to set the dependencies during the execution phase (in the generic task execution), doesn't work because Gradle don't allow to set dependencies after task execution. It show me the error:
Cannot call Task.dependsOn(Object...) on task ':distributeTest_CppForArduinoYun_OpenWrt' after task has started execution.
I tried also change the project evaluation order with:
subprojects.each { subproject -> evaluationDependsOn ( subproject.path ) }
but without any success.
When I printed the numbers of task for each subproject, it show me the NativeBinaries projects still with zero tasks until after first task execution.
EDIT:
How @Opal suggest, I tried to use the project.afterEvaluate
statement but it didn't work. When I printed the tasks number of each project, in his 'afterEvaluate' event; the NativeBinaries projects still have zero tasks.
Here you can find a simple multi-project to test this issue. Ther're 2 projects: Root and ProjA. The root project apply the Distribution plugin that register printTasks() function to the following events in the root project:
project.beforeEvaluate
(NOT raised)project.afterEvaluate
project.getGradle().projectsEvaluated
project.getGradle().projectsLoaded
(NOT raised)project.getGradle().taskGraph.whenReady
project.allprojects.each { p-> p.afterEvaluate }
project.getGradle().addBuildListener
buildStarted
(NOT raised)settingsEvaluated
(NOT raised)projectsLoaded
(NOT raised)buildFinished
projectsEvaluated
Events project.afterEvaluate
, project(gradle).afterEvaluate
, project(ProjA).afterEvaluate
, BuildListener::projectsEvaluated
and project.getGradle().projectsEvaluated
prints:
Project | Tasks count
--------|------------
gradle | 1
ProjA | 0
Only events project.getGradle().taskGraph.whenReady
and BuildListener::
prints:
Project | Tasks count
--------|------------
gradle | 1
ProjA | 8
Unfortunately this two events are reised too late and I can't add dependencies to tasks.
Any idea how I can solve it?
The event to register to find all project's tasks defined is rootProject.gradle.taskGraph.whenReady
. If we print the tasks for any projects when this event is raised, then we can find all task we need to build native binaries.
All other infos about binaries generation are content in {native_proj}.binaries
.