Skip to content

KSP task (non-)registration happens too soon #1789

@ZacSweers

Description

@ZacSweers

I have a gradle plugin that tries to conditionally enable KSP and add relevant KSP processors to it. However, I found that KSP's task registration can be unintentionally deleted by a simple project.afterEvaluate in gradle, resulting in the task never being registered and thus not run.

Example

// in build.gradle.kts, or a gradle plugin

project.afterEvaluate {
  if (enableKsp) {
    pluginManager.apply("com.google.devtools.ksp")

    dependencies.add("ksp", "some.ksp:processor:1.0.0")
  }
}

will result in KSP being applied but no ksp*Kotlin task ever being registered and thus never running. If I add any dependency to the ksp configuration (even one without any KSP processors in it), it works and picks up the later-added dependency too.

I think I would expect this to always register the KSP task, then conditionally no-op at task-action-time rather than try to conditionally avoid adding the task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions