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

Add excludedSources to the KSP extension object #1793

Merged
merged 1 commit into from Mar 20, 2024

Conversation

bitspittle
Copy link
Contributor

This new property allows users to create a Gradle task that generates Kotlin code, which can then get excluded by KSP's processing step.

This can help avoid circular Gradle dependency issues, such as in the case where KSP generates an intermediate file (like a resource) which a Gradle plugin then consumes and uses to generate its own Kotlin source.

Without this change, KSP would want to rerun when the new source got generated, which upsets Gradle because it already ran.

The following is one example of using the excludedSources property:

val generateCodeTask = tasks.register("generateCodeTask") {
    val outputDir = project.layout.buildDirectory.dir("generated/src")
    outputs.dir(outputDir)

    doLast {
        /* ... generate code into outputDir ... */
    }
}

ksp.excludedSources.from(generateCodeTask)

kotlin {
    sourceSets.main {
        kotlin.srcDir(generateCodeTask)
    }
}

Bug #1791

This new property allows users to create a Gradle task that generates Kotlin code, which can
then get excluded by KSP's processing step.

This can help avoid circular Gradle dependency issues, such as in the case where KSP
generates an intermediate file (like a resource) which a Gradle plugin then consumes
and uses to generate its own Kotlin source.

Without this change, KSP would want to rerun when the new source got generated, which
upsets Gradle because it already ran.

The following is one example of using the `excludedSources` property:

```kotlin
val generateCodeTask = tasks.register("generateCodeTask") {
    val outputDir = project.layout.buildDirectory.dir("generated/src")
    outputs.dir(outputDir)

    doLast {
        /* ... generate code into outputDir ... */
    }
}

ksp.excludedSources.from(generateCodeTask)

kotlin {
    sourceSets.main {
        kotlin.srcDir(generateCodeTask)
    }
}
```

Bug google#1791

Co-authored-by: David Herman <bitspittle@gmail.com>
Co-authored-by: Dennis Tsar <45399002+DennisTsar@users.noreply.github.com>
@ting-yuan ting-yuan self-requested a review March 16, 2024 06:00
@ting-yuan ting-yuan self-assigned this Mar 16, 2024
@ting-yuan ting-yuan merged commit f8e3907 into google:main Mar 20, 2024
3 checks passed
@ting-yuan
Copy link
Collaborator

Thanks for the patch!

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

Successfully merging this pull request may close these issues.

None yet

2 participants