How can I run a task BEFORE Kotlin compiles the source classes?
I'm generating classes based on
.yml
files for localization files, if there is a key
commands.hello: "Hello {user}!"
, a class + function is generated named
I18nKeysData.Commands.Hello(name: Any)
Currently what I'm doing is this
// HACKY WORKAROUND!!!
// This makes the generateI18nKeys task to always be ran before the compileKotlin step
// We need to do this (instead of using withType) because, for some reason, it doesn't work and the task isn't executed.
//
// We need to keep it within the "afterEvaluate" block because, if it isn't, the compile*InsertStuffHere* tasks won't exist!
// <https://stackoverflow.com/a/58763804/7271796>
project.afterEvaluate {
project.tasks.filter { it.name.startsWith("compileKotlin") }.forEach {
it.dependsOn(task)
}
}
But I think it is very hacky and it broke in Kotlin 1.6.20-M1 because they added a new
compileCommonMainKotlinMetadata
task, so I wonder if there is a better solution for this