I'm trying the latest `2.1.0-RC-1.0.27` with `useK...
# ksp
r
I'm trying the latest
2.1.0-RC-1.0.27
with
useKSP2=true
and I have some strange problems. More in thread.
My processor works fine but only after fresh
clean
of the project. But when I run the process again, some existing files generated by the previous compilation in the
generated/ksp/metadata
directory (and only in this directory) are somehow converted to directories. And the processor fails with with IO exception, because it can't write the files anymore.
I'm using some "hacks" learned from https://github.com/google/ksp/pull/1021 to support my multiplatform project but it works fine with KSP1.
I'm only using
codeGenerator.createNewFile()
to create files, so it seems somehow this function converts an existing file to a directory?! It doesn't make any sense for me.
d
We are also experiencing this issue. I have debugged it and found something. First, I’d like to check that in your case in the generated module you make
srcDir(..path to generated sources...)
If yes, try removing it, the problem should be gone. But of course, after that the compilation will start to fail. To put it short, the problem stems from the fact that
KspGradleConfig
’s field `commonSourceRoots`contains individual kotlin files, not the directories of source roots. And later, in
KotlinSymbolProcessing:221
(on tag 2.0.21-1.0.27) we have
root.forEach { it.mkdirs() }
Which results in creating directories of the form
generated/…/MyGenerated.kt
Every other invocation (or after clean) it works ok because when it doesn’t find the generated kt files, they don’t get into the source roots collection. It also doesn’t cause problems with non-generated normal kt files, because
mkdirs()
checks for exists first and if the “directory” exists (even if it’s a file really) it just does nothing. The same happy coincidence doesn’t happen for generated files because after getting into the source roots collection they get cleared by ksp internals, and at the moment of
mkdirs()
they already don’t exist, making them a victim of
mkdirs
. A few questions: 1. Is it true that
commonSourceRoots
collection is supposed to contain directories, not kt files, in which case
mkdirs
would make sense 2. Should I create an issue with the above findings? 3. Is adding
srcDir(.../generated/...)
still the correct way to make generated sources visible to non-generated code and idea?
I was intending to send this ☝️ to the channel as well, sorry for separate message
t
1. The
mkdirs
was removed last week and will be made available today in 1.0.29. 2. srcDir(generated) is no longer needed for IDE
d
I confirm that for us, the problem of wrong .kt directories is gone. Thank you! However, regarding srcDir, maybe I didn’t mention that I’m talking about multiplatform case. What I observe, is that if I remove
srcDir("build/generated/ksp/metadata/commonMain/kotlin")
then not only idea doesn’t mark the directory as sources, but also gradle compilation fails, given that in my hand-written sources there are references to generated ones.