This message was deleted.
# plugin-development
s
This message was deleted.
v
afterEvaluate
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.
j
@Vampire thanks for reply. What I'm doing.. • create
generateCode
task • add output folder of
generateCode
as another jvm/android/kmp sourceDir • ensure generateCode runs before compile code task and based what you said
Copy code
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 ?
v
Exactly, your last step should just not be necessary if done properly. Add I said, not sure about KMP specifics, but in a normal Java project you would just do
sourceSets { 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.
j
amazing, thanks a lot šŸ‘
šŸ‘Œ 1