1

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?

Secort
  • 43
  • 5
  • Try to add your logic in closure passed as an argument to: `project.afterEvaluate`. – Opal Oct 10 '15 at 18:19
  • When I set dependencies when afterEvaluate() is raised, Gradle can't find tasks. This is because the NativePlugin had not yet been executed. So a good solution can be add my logic after the NativePlugin execution. Right? How I can do it? – Secort Oct 12 '15 at 15:46
  • In `project.afterEvaluate` all the plugins are already applied - so the task should exists. Do you have a runnable example? – Opal Oct 12 '15 at 16:01
  • Hi @Opal, I added more infos in the question text and the runnable example. – Secort Oct 13 '15 at 12:17
  • As far as I see it will be better to ask directly at https://discuss.gradle.org/. Share a link to the discussion please. – Opal Oct 16 '15 at 08:27

1 Answers1

1

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.

Secort
  • 43
  • 5