I'm trying to write tests that use generated code,...
# ksp
f
I'm trying to write tests that use generated code, and while my IDE thinks everything is perfectly fine the build fails because of missing symbols when running
test
after making changes and having built before (it works after clearing the
.gradle
cache). I have of course added the generated sources to the source set like so
Copy code
kotlin {
    sourceSets {
        main {
            kotlin.srcDir("build/generated/ksp/main/kotlin")
        }
        test {
            kotlin.srcDir("build/generated/ksp/test/kotlin")
        }
    }
}
is there anything else that can be done in order to allow access to generated sources in tests?
j
since clearing gradle cache works, can you try disable incremental to see if this issue can resolve?
f
Oh great, it seems to work by disabling
incremental
on the
KotlinCompile
tasks, thank you very much!
j
@Ting-Yuan Huang I think this might be interesting for you. I feel the problem is with test source set is not included into incremental calculation(which I am not sure if it should though)
t
@F0X Would you mind to share a test project so that we can reproduce and debug?
f
Sorry it took so long @Ting-Yuan Huang, I just tried setting up a simple project to confirm this, but so far the problem doesn't occur. I believe it may be related to the generated sources in my actual project both using other sources in the project they are generated in and being used by the project, so a kinda weird two-way dependency. Here's the project where it happened, specifically with
core
using
internal-processor
(ignore my bad code 🙂). Maybe I'll manage to reproduce it in my testing setup later on.
t
I can reproduce with the project by commenting out the block which disables incremental compilation of
compileTestKotlin
. I compared the compiler arguments (incremental vs non-incremental) and they are exactly the same. The generated source is passed to compiler, and it does exist on the disk with correct content. In this particular case, it could be an issue of how KSP registers the generated source to the compiler, or simply a bug in the compiler. More investigation is needed.
👏 1