https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jiri Bruchanov

09/21/2023, 7:56 AM
Hi, anyone who could help ? I'm building small gradle plugin which generates kt code. I'm facing following error
Copy code
Reason: Task ':shared:compileCommonMainKotlinMetadata' uses this output of task ':shared:generateCode' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
So trying to add a dependency/relation to specify the order between KMP task and my generateCode task. I'm not sure how to get
:shared:compileCommonMainKotlinMetadata
task reference though, using simple
target.tasks.findByName
returns null even if I do that in
afterEvaluate
block. What would be the correct way to do it ?
trying also use
Copy code
val provider = target.tasks.register("compileCommonMainKotlinMetadata")
provider.configure { t ->
    t.mustRunAfter(generateCodeTaskProvider)
}
that fails unfortunately later when actual KMP tries to create the task
Copy code
Cannot add task 'compileCommonMainKotlinMetadata' as a task with that name already exists.
a

Adam S

09/22/2023, 9:29 AM
What's your Gradle config? I would guess that you're adding a new directory, something like
srcDir("build/generated-sources/kotlin")
? If that's the case, then instead you'll want to pass a task reference instead, and that task has an output directory. That way Gradle will automatically know it needs to run the task in order for the sources to be ready, and additionally any tasks that use those sources will understand the requirement. Try taking a look at this answer: https://stackoverflow.com/a/74771876/4161471
j

Jiri Bruchanov

09/22/2023, 9:33 AM
yup, that's what I was doing... I didn't realise I can pass the task itself as a "source dir" which the issue
👍 1
2 Views