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

Update "Make IDE aware of generated code" documentation #168

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,19 @@ context.startService(intent)

## Make IDE aware of generated code

To have code generated by Exercise recognized in your IDE, add the following to your root `build.gradle.kts`:
To have code generated by KSP (e.g. Exercise) recognized in your IDE, add the following to your root `build.gradle.kts`:

```kotlin
allProjects {
withPluginWhenEvaluated("com.google.devtools.ksp") {
extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension>()
?.sourceSets
?.forEach { sourceSet ->
sourceSet.kotlin.srcDir("build/generated/ksp/${sourceSet.name}/kotlin")
}
}
}

fun Project.withPluginWhenEvaluated(plugin: String, action: Project.() -> Unit) {
pluginManager.withPlugin(plugin) { whenEvaluated(action) }
}

fun <T> Project.whenEvaluated(action: Project.() -> T) {
if (state.executed) action() else afterEvaluate { action() }
subprojects {
project.plugins.whenPluginAdded {
if (this is org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin) {
project.extensions.configure<org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension> {
sourceSets.forEach { sourceSet ->
sourceSet.kotlin.srcDir("build/generated/ksp/${sourceSet.name}/kotlin")
}
}
}
}
}
```

Expand Down