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

Does Showkase generate code too early in the build lifecycle? #402

Open
oheyadam opened this issue Dec 17, 2024 · 0 comments
Open

Does Showkase generate code too early in the build lifecycle? #402

oheyadam opened this issue Dec 17, 2024 · 0 comments

Comments

@oheyadam
Copy link

I’m rolling out an extension onto our convention plugins to selectively opt-into Showkase. the API surface looks like this

myExtension {
  optInto {
    showkase(true)
  }
}

The value set here is evaluated in our convention plugin and is used to selectively add the Showkase dependencies to modules that opted in

class ComposeConventionPlugin : Plugin<Project> {

    override fun apply(target: Project): Unit = target.run {
        val handler = myExtension().optInHandler
        handler.applyTo(this)
    }
}

// part of the handler class, which in turn is part of my registered extension
internal fun applyTo(project: Project) {
  // This must happen in afterEvaluate to ensure the extension was configured
  project.afterEvaluate {
    if (enableShowkase.getOrElse(false)) {
         pluginManager.apply(libs.plugins.ksp.get().pluginId)
         extensions.configure<KspExtension> {
           arg("skipPrivatePreviews", "true")
         }
         dependencies {
           "implementation"(libs.showkase.annotation)
           "debugImplementation"(libs.showkase)
           "kspDebug"(libs.showkase.processor)
         }
    }
  }
}

We must do this in afterEvaluate because if you do it any earlier, Gradle wouldn’t have configured the extension yet. However, this seems to be too late for the ShowkaseProcessor class.

This processor seems to kick in quite early in the lifecycle and doesn't wait for all projects in the graph to be configured. Is there a way for me to tell the processor to kick into gear at a later point in time when my code is ready, or is this just how KSP processors work?

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

No branches or pull requests

1 participant