What's the official way to add a custom code gener...
# gradle
h
What's the official way to add a custom code generator that should run for each sourceSet with custom dependencies added by the user? Should I use kotlin.sourceSets.configureEach, create my new task wired to the kotlin.srcSetDir and add a custom dependency function to the KotlinDependencyHandler? (BTW any plans to use the new Gradle DependencyCollector?)
v
https://youtrack.jetbrains.com/issue/KT-58759
And after 2.0 release we will redesign/rethink the
KotlinDependencyHandler
in favor of more maintainable and fine-tuned approach.
see: https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyAdder.html
With "add a custom dependency function to the KotlinDependencyHandler" consider using a Gradle extension, not a Kotlin extension function, so that users of both DSL are on board and do not need an import, if you need that
h
But there is no DependencyCollector support, yet, is it?
🚫 1
v
Not that I know of. They just mentioned in that issue over which I stumbled yesterday that they will redesign the thing. (
DependencyAdder
is the old name of
DependencyCollector
)
t
also this issue is relevant
h
Honestly, I don't understand why KGP needs another implementation. What's wrong with the standard way/Gradle API, also mentioned by Anton?
t
• there is a use-cases when KGP consumers want to get source set sources, but without generated one •
prepareKotlinIdeaImport
task is only added in KMP • Import could gather which tasks generate something and trigger them after main import will finish, so users will not see red code that referencing generated symbols
and probably there are more to this
v
Besides getting only non-generated sources, if using the normal Gradle way of just setting the generation task as
srcDir
, shouldn't it be sufficient if the IDE import just tells Gradle "give me all source files" which should then automatically trigger the generation tasks? It does not even do anything with the files.
t
shouldn't it be sufficient if the IDE import just tells Gradle "give me all source files" which should then automatically trigger the generation tasks?
It will be kind of heavy part of import process, so we want to delay it as much as possible (and maybe make optional). Overall we are still in discovery phase how to do it.