Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kspTestKotlin output seems to clobber kspKotlin output #157

Closed
mvdbos opened this issue Nov 18, 2020 · 5 comments · Fixed by #162
Closed

kspTestKotlin output seems to clobber kspKotlin output #157

mvdbos opened this issue Nov 18, 2020 · 5 comments · Fixed by #162
Assignees
Labels
bug Something isn't working P2 affects usability but not blocks users
Milestone

Comments

@mvdbos
Copy link

mvdbos commented Nov 18, 2020

I have two classes annotated with the same annotation. One in the main sourceset, one in the test sourceset.
In my processor, I use CodeGenerator to write the generated output files.

If I run only kspKotlin, the generated output is correctly placed in build/generated/ksp/src/main/kotlin/packagename/SomeFile.kt
If I subsequently run compileKotlin, the .class file for SomeFile.kt is correctly placed in the build/classes dir hierarchy. The generated source is untouched.

Now when I run kspTestKotlin, the generated source for the test sourceset is correctly placed in build/generated/ksp/src/xitest/kotlin/packagename/SomeTestFile.kt

Unfortunately the previously generated source for the main sourceset at build/generated/ksp/src/main is removed. Even the whole main subdir is removed. This not causing problems for running the code, since the .class files remain, but the IDE can now no longer find the source, which is very inconventient.

I did some digging in the code of Ksp, but it is not clear to me why this happens. Could you help me find the cause?

@mvdbos
Copy link
Author

mvdbos commented Nov 18, 2020

I did another test, and I can confirm that any invocation of KspTask clobbers build/generated/ksp.

When I manually add a subdir, e.g. build/generated/ksp/foo, and run either kspKotlin or kspTestKotlin, the dir build/generated/ksp get recreated.

Additionally, when I print the output dirs for the different KspTasks in Gradle like this, it indeed shows the output dir to be build/generated/ksp:

    withType<com.google.devtools.ksp.gradle.KspTask> {
        println(name)
        outputs.files.forEach { println(it.absolutePath) }
    }

@mvdbos
Copy link
Author

mvdbos commented Nov 18, 2020

When I do the same for tasks of type KotlinCompile, I see that the output dir is suffixed with the sourceset, which would prevent this clobbering from happening. Is this perhaps an idea to solve this?

@mvdbos
Copy link
Author

mvdbos commented Nov 18, 2020

Could it be that this causes it?

InternalTrampoline.KotlinCompileTaskData_register(kspTaskName, kotlinCompilation, project.provider { destinationDir })

@mvdbos
Copy link
Author

mvdbos commented Nov 18, 2020

Please have a look at #158. It addresses the issue for me, but I am not sure if this is the right way to adress this.

@ting-yuan
Copy link
Collaborator

A KspTask is basically a KotlinCompile with incremental = false. On each execution, the outputs are cleaned. KspTestKotlin shares the same destinationDir with KspKotlin and I guess this is why the outputs of KspKotlin is cleaned when running KspTestKotlin. Will make destinationDir task specific as well.

@ting-yuan ting-yuan added bug Something isn't working P2 affects usability but not blocks users labels Nov 20, 2020
@ting-yuan ting-yuan added this to the 2020Q4 milestone Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2 affects usability but not blocks users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants