-
Notifications
You must be signed in to change notification settings - Fork 281
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
IDE not indexing generated source #37
Comments
For now, I've manually supported this like so sourceSets {
main {
java {
srcDir(file("build/generated/ksp/src/main"))
}
}
test {
java {
srcDir(file("build/generated/ksp/src/test"))
}
}
} |
The IDE extension, where KaptProjectResolverExtension resides, is bundled with the IntelliJ Kotlin plugin. Therefore that approach doesn't work for now. |
Moving this to Q4 as it depends on upstreaming, which won't happen in Q3. |
Deferring again to 2021Q1. |
buildTypes {
getByName("debug") {
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/debug/kotlin"))
}
}
}
getByName("release") {
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/release/kotlin"))
}
}
}
} I am using above script in build.gradle.kts and working as well for now. |
As a slight modification to the above, here's an approach that's a little more compact and flexible (for Android projects): applicationVariants.all {
val variantName = name
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/$variantName/kotlin"))
}
}
} |
It's good for newcomers to know of this workaround while google#37 is open.
It's good for newcomers to know of this workaround while #37 is open.
We use this logic in our tooling: plugins.withId("com.google.devtools.ksp") {
the<BaseExtension>().variants.configureEach {
addJavaSourceFoldersToModel(layout.buildDirectory
.dir("generated/ksp/$name/kotlin").get().asFile)
}
} having: val BaseExtension.variants: DomainObjectSet<out BaseVariant>
get() = when (this) {
is AppExtension -> applicationVariants
is LibraryExtension -> libraryVariants
is TestExtension -> applicationVariants
else -> error("unsupported module type: $this")
} |
For android folks who want to set kotlin sourceSets, we can configure it this way android.applicationVariants.all { variant ->
kotlin.sourceSets {
def name = variant.name
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
} |
This worked for us in an android library module.
|
I'd like to warn about issues in previously mentioned options. applicationVariants.all {
val variantName = name
sourceSets {
getByName("main") {
java.srcDir(File("build/generated/ksp/$variantName/kotlin"))
}
}
}
configure<BaseExtension> {
buildVariants.configureEach {
sourceSets {
named(name).configure {
java.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
} This alternative has another issue. First clean build:
There were only sources as input for this task.
Here we see generated files as an addition to original sources. |
For build.gradle.kts android.applicationVariants.all {
kotlin {
sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
} |
@eugene-krivobokov can you suggest correct solution for Android when using build variants? Thank you 🙏 |
Unfortunately, I haven't found it yet. |
After upgrading to Android Studio Electric Eel the following solution didn't work anymore: android {
libraryVariants.all {
kotlin.sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/${name}/kotlin")
}
}
}
} But this one seems to work fine: android {
kotlin {
sourceSets {
debug {
kotlin.srcDir("build/generated/ksp/debug/kotlin")
}
release {
kotlin.srcDir("build/generated/ksp/release/kotlin")
}
}
}
} |
None of the above solutions work on The solution that leinardi gave was working around canary 4 but I don't remember in which version it stopped. |
it works well on Android Studio. |
Fixed in e81d01f and will be available in 1.0.9. There should no longer workarounds be needed. |
@ting-yuan |
Looks like that kapt has an IDE plugin to achieve this: KaptProjectResolverExtension.kt
We either need to copy it over, or simply tell users to mark generated source root themselves in the preview.
The text was updated successfully, but these errors were encountered: