I seem to remember a custom gradle hook for IDEs to run for code generation. My situation is using grpc, if a branch has changes to the proto definitions, I need the grpc generation to run whenever I switch branches. Obviously it works when you run, but would be nice not to stare at red lines until the first build.
v
Vampire
06/02/2023, 3:59 PM
Not aware what you could mean.
But you could define a lifecycle task called
generate
in your build that depends on all code generation tasks and then configure your IDE to run that task before or after sync.
You can also configure this automatic task-running using the
idea-ext
plugin if your IDE is IntelliJ.
Vampire
06/02/2023, 4:00 PM
Actually, if the code generation tasks are properly registered as `srcDir`s, the IDE sync could maybe trigger the getting of the source files and thus cause the generating tasks to be executed. But I'm not aware that either IDE is doing that currently.
t
Trevor Stone
06/02/2023, 4:52 PM
Copy code
// This triggers code-gen immediate on gradle sync
afterEvaluate {
tasks
.maybeCreate("prepareKotlinIdeaImport")
.dependsOn(tasks.getByPath(":${project.name}:kspKotlin"))
}