Avoid Gradle to call child task automatically?

I have :myRootProject:myTask that is adding automatically a dependency on :myRootProject:myChildProject:myTask

I do not want Gradle to do that, because myChildProject:myTask depends on myRootProject:myTask and I get a circular dependency

How can I avoid this?

Calling any task automatically calls all child project tasks with that same name. This is what allows the use of something like ‘gradle build’ to build your entire project and all subproject without defining any explicit dependencies. If you do not want this behavior you’ll have to rename one of the tasks so that their names are unique. Additionally, a child should not typically depend on its parent. Perhaps you could provide some more detail on your use case?

I have a project “A” that has a folder called “examples” with several projects that are meant to be a support tools or help tools for “A”, so:

A/build.gradle A/examples/example1/build.gradle A/examples/example2/build.gradle

Obviously, the examples need the code of the parent to be compiled, and we want the examples to be compiled when you compiled the main program.

How would you do it? How would be the file structure in a typical gradle project if we want to scenario?

I have just found a dirty solution: In A/build.gradle just put a “project.getChildProjects().clear()” But I am not sure if it is the best solution.

I would probably either create a subproject under A called ‘common’ or something similar and have the example projects depend on it (siblings depending on each other is typically fine). Alternatively, create a Project B with the examples in it, and have B depend on A. In general you just simply want to avoid a structure which would require a child to depend on a parent because that typically introduces a cyclic dependency, as you have observed.

Then, regarding your first solution. Your ‘common’ is my ‘examples’ right? So, if I have :a:examples:example1:dist that depends on :a:dist. I could have a :a:examples:dist that depends on :a:dist, and it would fix the problem? did I understand you?

No, that still introduces and child -> parent dependency. I would suggest something like:

+--- :A:examples
+--- --- :A:examples:common
+--- --- :A:examples:example1
+--- --- :A:examples:example2

Then :a:examples:example1 and :a:examples:example2 would both depend on :a:examples:common. The :a:examples project would be effectively empty.

Wow, I do not quite like that, beside that it adds more complications in my infrastructure (I have simplified things a lot in this post)… I think I will just take this project out and call it “A_Examples” or something similar. Thanks a lot.