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:
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 examples:example1:dist that depends on dist. I could have a examples:dist that depends on dist, and it would fix the problem? did I understand you?
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.