Is there a simple way to add generated java code i...
# multiplatform
g
Is there a simple way to add generated java code in a KMP project? I've defined
jvm { withJava() }
but looks like if I only do
val jvmTest by getting { kotlin.srcDir("build/generated/.../jvmTest/java") /* ... */ }
those classes are not compiled.
1
Alright, looks like asking the question is enough for my brain to find the answer, sorry for the notification... Keeping the answer here if ever someone get the same question:
Copy code
val jvmTest by getting {
    java.sourceSets {
        getByName("test").java.srcDirs("build/generated/.../jvmTest/java")
    }
}
j
Is the generation task running first? Generally you should be adding the task which generates the file to the source set and never be referencing folders directly. Gradle will automatically pick up the
@OutputDirectory
of the task and automatically create the necessary task dependencies.
g
So actually I'm using KSP to produce proto files from kt files, then I use protoc to generate kotlin+java files. Because the official gradle protoc plugin doesn't support KMP, I've made a (temporary) task that run protoc from cli, and that task dependsOn the ksp one. If I go further with this patch I'll try to use @OutputDirectory on this task. Thanks for the tip!
109 Views