I decided to move my build logic into a gradle plu...
# gradle
m
I decided to move my build logic into a gradle plugin for deduplication, but when calling
apply<KotlinMultiplatformPluginWrapper>()
I get the error
Copy code
Caused by: org.gradle.api.internal.AbstractMutationGuard$IllegalMutationException: Project#afterEvaluate(Action) on project '...' cannot be executed in the current context.
	at org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginKt.whenEvaluated(KotlinMultiplatformPlugin.kt:236)
What should I do to fix this?
t
I think it depends on your plugin code. Generally such message indicates your plugin tries to apply MPP plugin in some configuration action. For example such approach may cause it:
Copy code
tasks.named("some-task") {
    project.plugins.apply<KotlinMultiplatformPluginWrapper>()
}
m
It's in my own plugin's apply function:
Copy code
open class MyPlugin : Plugin<Project> {
    override fun apply(target: Project) = with(target) {
        apply<KotlinMultiplatformPluginWrapper>()
    }
}
t
that is strange. Could it be your plugin is applied in such configuration block?
m
It looks like calling
val jvmMain by sourceSets.registering
in the kotlin{} block caused it, strange
t
yes, as it is lazy configuration block. I think you could change it to
by sourceSets.creating
to eager create source set
in this particular case eager creation should be ok
209 Views