Hello folks! Is there a way to produce classes fro...
# ksp
c
Hello folks! Is there a way to produce classes from main sources to only test sources?
j
you mean only generate code in test directory?
c
yes
j
maybe explicitly running ksp task for test task only? Is that an option for you?
c
kspTest("our-processor")
produces classes from test sources to test sources! I want to read from main sources and produce for test sources!
j
I see what you mean, can you do this: run ksp on main source for generating the test code you want, and include that generated source in test task’s input?
c
hmm how do I do something like this? is there a sample project/example I can look at?
j
something like this? I am not sure if this will work for you but that’s my idea.
Copy code
kotlin {
    sourceSets {
        test {
        kotlin.srcDir("$buildDir/generated")
        }
    }
}
c
will try it thanks!
👍 1
another question if you know 😛
do you think there is a way to make the ksp task run only when test task will run?
j
it should be doable, just need writes in build script, I can try to play around with gradle when I got time.
c
atm I do something like this but it doesn not work perfect
Copy code
gradle.taskGraph.whenReady {
    val willTestsRun = gradle.taskGraph.allTasks.any {
        it.name.startsWith("test")
    }
    ksp.arg("ourprocessor:willTestsRun", "$willTestsRun")
}