Robert Jaros
11/08/2024, 6:58 AM2.1.0-RC-1.0.27
with useKSP2=true
and I have some strange problems. More in thread.Robert Jaros
11/08/2024, 7:02 AMclean
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.Robert Jaros
11/08/2024, 7:05 AMRobert Jaros
11/08/2024, 7:06 AMRobert Jaros
11/08/2024, 7:09 AMcodeGenerator.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.Daniil Elovkov
11/27/2024, 9:03 PMsrcDir(..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?Daniil Elovkov
11/27/2024, 9:05 PMTing-Yuan Huang
11/27/2024, 9:29 PMmkdirs
was removed last week and will be made available today in 1.0.29.
2. srcDir(generated) is no longer needed for IDEDaniil Elovkov
11/28/2024, 9:27 AMsrcDir("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.