Skip to content

Arrange dependencies of KSP tasks and LaunchSpineCompiler in afterEvaluate #62

@alexander-yevsyukov

Description

@alexander-yevsyukov

Currently LaunchSpineCompiler task class arranges the dependency with a KSP task using the code below:

private fun LaunchSpineCompiler.setDependencies(sourceSet: SourceSet) {
    val project = project
    dependsOn(
        project.compilerRawArtifact.buildDependencies,
        project.userClasspath.buildDependencies,
    )
    val launchTask = this
    project.findJavaCompileFor(sourceSet)?.dependsOn(launchTask)
    project.findKotlinCompileFor(sourceSet)?.dependsOn(launchTask)

    val kspTask = KspTaskName.of(sourceSet)
    project.tasks.findByName(kspTask.value())?.dependsOn(launchTask)
}

This function is called from LaunchSpineCompiler.applyDefaults(sourceSet: SourceSet).
The applyDefaults() function is called as an action in createLaunchTask():

private fun Project.createLaunchTask(
    sourceSet: SourceSet,
): TaskProvider<LaunchSpineCompiler> {
    val taskName = CompilerTask.nameFor(sourceSet)
    val result = tasks.register<LaunchSpineCompiler>(taskName) {
        applyDefaults(sourceSet)
    }
    return result
}

The createLaunchTask() is called when Spine Compiler Gradle plugin is applied to a project.

The problem with the current code is that KSP task is not yet registered at the time we apply the Compiler Gradle plugin.

This is why the consumers of the Compiler have to apply the code like given below in their build files:

afterEvaluate {
    tasks.named("kspTestFixturesKotlin") {
    mustRunAfter("launchTestFixturesSpineCompiler")
}

The obvious fix would be to do the same in our code. But trying to apply the below code under applyDefaults() causes Gradle error in integration tests:

project.afterEvaluate {
    setDependencies(sourceSet)
}

The error says that afterEvaluate cannot be executed "in this context".

It looks like the code setting the dependencies should be pulled up to the level of the Gradle plugin after the LaunchSpineCompiler tasks are created.

Metadata

Metadata

Labels

No labels
No labels

Type

No fields configured for Bug.

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions