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

KSP resolves classes that are not available to the app #198

Closed
yigit opened this issue Dec 19, 2020 · 4 comments
Closed

KSP resolves classes that are not available to the app #198

yigit opened this issue Dec 19, 2020 · 4 comments
Assignees
Labels
bug Something isn't working P1 major features or blocking bugs
Milestone

Comments

@yigit
Copy link
Collaborator

yigit commented Dec 19, 2020

Seems like something is wrong with how classpaths are set for android apps (couldn't repro w/ jvm sample but that might be my mistake).

See the attached project where I have an android module and a ksp processor module.

The KSP processor checks for the availability of the javax.annotation.processing.Generated class and adds that annotation if available.
Unfortunately, KSP does return that class even though it is not available to the app, causing compilation failure.

Make sure to compile the attached project with a JDK where that class is available. (I'm using J11). I'm guessing it is why the class shows up.

I tried adding the following line to the app module but didn't help:

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile.class).configureEach {
    it.kotlinOptions.jvmTarget = "1.8"
}

ksp-android-classpath-bug.zip

@ting-yuan ting-yuan self-assigned this Dec 21, 2020
@ting-yuan ting-yuan added bug Something isn't working P1 major features or blocking bugs labels Dec 21, 2020
@ting-yuan ting-yuan removed their assignment Dec 21, 2020
copybara-service bot pushed a commit to androidx/androidx that referenced this issue Dec 22, 2020
There is an existing bug in KSP where it returns classes that are not
available to the application, causing room to find j9 generated class
even when it doesn't exist.

This CL disables the generated annotation support in KSP for now until
the issue is resolved.
google/ksp#198

Bug: 160322705
Test: disabled the related test

Change-Id: I4bf8f47f124a2288adb0b99e80648a4f5a9a533a
@ting-yuan ting-yuan added this to the 2021Q1 milestone Dec 31, 2020
@eamonnmcmanus
Copy link
Member

FWIW auto-common changed from trying to tell whether javax.annotation.processing.Generated is present to just checking the source version for what are probably reasons similar to the issue here.

@yigit
Copy link
Collaborator Author

yigit commented Jan 25, 2021

interesting, i think we might be using the old version (i checked the impl while copying it).
That being said, i don't think KSP provides us that information right now.

Also, org.gradle.java.home=JDK_8 is a possible workaround but that is still limited to compiling w/ java8 and most clients are already above that.
related kapt issue: https://youtrack.jetbrains.com/issue/KT-32804

@ting-yuan ting-yuan self-assigned this Jan 25, 2021
@yigit
Copy link
Collaborator Author

yigit commented Jan 26, 2021

i found a workaround by calling setupCompilerArgs on the compile kotlin task in the KspTask.

Kapt uses something similar:
https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt#L502

but it is using the contributor. I've not debugged what is in it. Specifically, if it adds sources etc, that might be a problem. Otherwise, seems like a safe solution?

@ting-yuan
Copy link
Collaborator

Fixed in #270. Solution is what Yigit mentioned in the above.

copybara-service bot pushed a commit to androidx/androidx that referenced this issue Feb 6, 2021
* Removed workarounds in KspTypeElement about detecting constructors
since KSP now has an API to get check if a function is a constructor
* Removed the workaround for google/ksp#175
which seems to be working now. Instead, now we revert some override
calls if its jvm signatures won't match.
* Updated ksp integration test (room kotlin test app) to use the new
kspAndroidTest conffiguration.
* Removed the workaround for google/ksp#173
* Re-enabled @generated annotation for KSP:
  google/ksp#198
* Removed the log for https://github.com/android/kotlin/issues/133
  We'll still use custom logic because calling KSP will invoke the
descriptor APIs and current implementation is working fine.
* Fallback location test now also checks the KSP constructor case
 google/ksp#273

Bug: 160322705
Test: existing tests
Change-Id: I1aef81b0c7475a86d40d38456e765a469ca79de6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1 major features or blocking bugs
Projects
None yet
Development

No branches or pull requests

3 participants