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

Incremental KSP fails in Java/Kotlin mixed module #997

Closed
amandeepg opened this issue May 20, 2022 · 1 comment · Fixed by #1138
Closed

Incremental KSP fails in Java/Kotlin mixed module #997

amandeepg opened this issue May 20, 2022 · 1 comment · Fixed by #1138
Assignees
Labels
bug Something isn't working
Milestone

Comments

@amandeepg
Copy link

If we have the following files (a Kotlin annotation, a Java annotated class, and a Kotlin constants file):

com.example.ann.MyAnn

annotation class MyAnn(val value: String)

com.example.JavaClass

public class JavaClass {
    @MyAnn(KotlinConsts.ACTION2)
    public void f() {
    }
}

com.example.KotlinConsts

class KotlinConsts {
    companion object {
        const val ACTION = "REPLACE"
        const val ACTION2 = "REPLACE"
    }
}

With a processor that looks for MyAnn and throws an error if the annotation value isn't "REPLACE":

resolver
    .getSymbolsWithAnnotation("com.example.ann.MyAnn")
    .filterIsInstance<KSFunctionDeclaration>()
    .forEach { func ->
        val arg = func.annotations.first().arguments.first().value.toString()
        if (!arg.startsWith("REPLACE"))
            throw IllegalStateException(arg)
    }

Then if we run the processor once, KSP runs fine. Then if we change @MyAnn(KotlinConsts.ACTION2) to @MyAnn(KotlinConsts.ACTION), and run KSP again, it will run under incremental mode, then we can no longer read the argument value, the condition isn't true, and we throw the IllegalStateException.

With the attached project:
playground3.zip

./gradlew  :workload:kspKotlin
# Edit JavaClass to reference KotlinConsts.ACTION instead
./gradlew  :workload:kspKotlin
# Observe that KSP was not able to read the annotation value

This prevents us from enabling incremental mode, which prevents us from using KSP as without incremental, our time in processing is higher than with Kapt where we can use incremental compilation.

@neetopia neetopia added this to the 1.0.7 milestone Jun 9, 2022
@neetopia neetopia added the bug Something isn't working label Jun 9, 2022
@ting-yuan ting-yuan self-assigned this Aug 16, 2022
@amandeepg
Copy link
Author

Thanks! Confirmed that the fix works for the sample app submitted and the real application I discovered this in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants