Slackbot
09/21/2023, 7:40 AMVampire
09/21/2023, 8:17 AMafterEvaluate is almost never the proper solution. It usually just is symptom treatment, while introducing timing problems and race conditions. Why it does not work in this specific case, I don't know from the top of my head. Probably it uses afterEvaluate itself and one that is executed after yours for example.
The proper way would be tasks.matching { it.name == "..." }.configureEach { ... } (but don't use matching like that to depend on a task)
But actually, defining task ordering or dependencies manually is practically always a code smell anyway (except if a lifecycle task is on the left-hand side). You should usually better properly wire task outputs to task Inputs and by that get necessary task dependencies implicitly everywhere where needed. If you for example have a task that compiles sources and a task that buils a source jar and a task that generates sources. Now if you just add a dependency from the compile task to the generate task, you still miss a dependency from source jar task to the generate task. If you instead properly register the generate task itself as source directory for the source directory set, all source consuming tasks automatically have the necessary dependency implicitly. I'm not sure whether with KGP there is something special in that regard though right now.Jiri Bruchanov
09/21/2023, 8:36 AMgenerateCode task
⢠add output folder of generateCode as another jvm/android/kmp sourceDir
⢠ensure generateCode runs before compile code task
and based what you said
If you instead properly register the generate task itself as source directory for the source directory set
does it mean my thinking how to solve the problem is wrong ?
and my task itself should be somehow marked itself as source code "producer" task which would make it working automatically without extra configuration ?Vampire
09/21/2023, 8:49 AMsourceSets { main { java { srcDir(generateCode) } } then if the task properly declared it's outputs, they are considered source by all source consumers and they get necessary task dependencies automatically.Jiri Bruchanov
09/21/2023, 8:51 AM