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

Index annotation cannot be resolved on generated code by ksp #4911

Closed
ganadist opened this issue Sep 30, 2022 · 3 comments · Fixed by #4919
Closed

Index annotation cannot be resolved on generated code by ksp #4911

ganadist opened this issue Sep 30, 2022 · 3 comments · Fixed by #4919
Labels

Comments

@ganadist
Copy link

ganadist commented Sep 30, 2022

Glide Version: 4.14.1

Integration libraries: N/A

Device/Android Version: N/A

Issue details / Repro steps / Use case background:
Generated codes by KSP cannot be compiled after setup project as ksp guideline

  • generated codes by ksp
package com.bumptech.glide.`annotation`.ksp

@Index([
"class1",
"class2",
])
 public class GlideIndexer_GlideModule_Class1_Class2Module { 

@Index annotation is under com.bumptech.glide.annotation.ksp package, but kotlin compiler cannot reference it.
After add compileOnly configuration on dependency block, compile can be succeeded.

dependencies {
    ksp 'com.github.bumptech.glide:ksp:4.14.1'
    compileOnly 'com.github.bumptech.glide:ksp:4.14.1'
}
@sjudd sjudd added the bug label Sep 30, 2022
@sjudd
Copy link
Collaborator

sjudd commented Sep 30, 2022

Thanks for reporting this and providing the workaround. I don't see this in a single module project. Could you share your project structure? Do you have a single module, or multiple modules? If you have multiple modules, do the submodules contain LibraryGlideModules? Or an AppGlideModule?

@ganadist
Copy link
Author

ganadist commented Sep 30, 2022

Hello.
It seems this error raised on LibraryGlideModules module only.
Here is a sample project to reproduce compile issue.

$ git clone https://github.com/ganadist/VersionCodeDemo -b glide-ksp
$ cd VersionCodeDemo
$ ./gradlew :lib:glide:assemble
...
> Task :lib:glide:compileReleaseKotlin FAILED
e: lib/glide/build/generated/ksp/release/kotlin/com/bumptech/glide/annotation/ksp/GlideIndexer_GlideModule_com_example_mylib_LibraryModule.kt: (3, 2): Unresolved reference: Index


$  ./gradlew :lib:glide:assemble -PuseKsp=false 
...
> Task :lib:glide:kaptReleaseKotlin
Note: [2] Wrote GeneratedAppGlideModule with: [com.example.mylib.LibraryModule]

> Task :lib:glide:compileReleaseKotlin
> Task :lib:glide:extractReleaseAnnotations
> Task :lib:glide:compileReleaseJavaWithJavac

sjudd added a commit to sjudd/glide that referenced this issue Oct 5, 2022
The processor will produce a Index annotated class for each LibraryGlideModule in given compilation unit. If the Index annotation is in the ksp module, it will not be accessible in parent modules, causing a compilation failure. To work around that, we'll follow the same pattern as we did for Java and place the annotation in the annotations package, but with package private visibility.

Any compilation unit that uses our annotation processor must already
have a dependency on annotation, so the Index annotation will be
available.

Fixes bumptech#4911.
sjudd added a commit to sjudd/glide that referenced this issue Oct 6, 2022
The processor will produce a Index annotated class for each LibraryGlideModule in given compilation unit. If the Index annotation is in the ksp module, it will not be accessible in parent modules, causing a compilation failure. To work around that, we'll follow the same pattern as we did for Java and place the annotation in the annotations package, but with package private visibility.

Any compilation unit that uses our annotation processor must already
have a dependency on annotation, so the Index annotation will be
available.

Fixes bumptech#4911.
sjudd added a commit that referenced this issue Oct 7, 2022
The processor will produce a Index annotated class for each LibraryGlideModule in given compilation unit. If the Index annotation is in the ksp module, it will not be accessible in parent modules, causing a compilation failure. To work around that, we'll follow the same pattern as we did for Java and place the annotation in the annotations package, but with package private visibility.

Any compilation unit that uses our annotation processor must already
have a dependency on annotation, so the Index annotation will be
available.

Fixes #4911.
@Patek0000
Copy link

Glide Version: 4.14.1

Integration libraries: N/A

Device/Android Version: N/A

Issue details / Repro steps / Use case background:
Generated codes by KSP cannot be compiled after setup project as ksp guideline

  • generated codes by ksp
package com.bumptech.glide.`annotation`.ksp

@Index([
"class1",
"class2",
])
 public class GlideIndexer_GlideModule_Class1_Class2Module { 

@Index annotation is under com.bumptech.glide.annotation.ksp package, but kotlin compiler cannot reference it.
After add compileOnly configuration on dependency block, compile can be succeeded.

dependencies {
    ksp 'com.github.bumptech.glide:ksp:4.14.1'
    compileOnly 'com.github.bumptech.glide:ksp:4.14.1'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants