I have a custom gradle that I'd like to run before...
# gradle
a
I have a custom gradle that I'd like to run before executing any KMP task (i.e. compileKotlinJvm, compileKotlinJs, compileKotlinLinuxX64, e.t.c) is there a common task that all of these platform specific task do depend on that I can hook my custom task there?
I know have it as
Copy code
targets.configureEach {
        compilations.all {
            compileKotlinTask.dependsOn("generateCode")
        }
    }
Is there another better way?
e
going by the "generateCode" name, surely it would be better to add the task output to the sourceset? then all the compile dependencies would work automatically
v
As well as other tasks needing sources like doc tasks, source jar tasks, analysis tasks, ...
a
So, yes. The task output is already added the commonMain sourceSet, however, I was looking for any other better alternative (if it exists) so that when I call
compileKotlinJvm
then
generateCode
will be called as a dependency. Just adding the output to the sourceSet works if the code is already generated, and it doesn't if the code is not generated at all in the first place
e
is this Android? there's a bit of a mess there
but with normal JVM projects, assuming you're adding it correctly (e.g.
task.outputDir
not
file(dir)
), the task dependencies are tracked
a
Its not android at all. Let me try with
task.outputDir
I had it with
kotlin.srcDirs
v
You don't even need
task.outputDir
, just use
task
(as long as
outputDir
is the only output of the task
Implicit task dependencies are practically always preferable over explicit
dependsOn
which always is a code smell
a
roger, will test this again when I am back at my desk