Problem changing "apply plugin:" to "apply(plugin = ...)" within a configure closure

We are preparing the migration of our build to Kotlin DSL by replacing all single quote by double quote, adding missing parenthesis in function call and so on.
All is going pretty well except for a transformation of apply plugin: “some plugin” to apply (plugin = “some plugin”) which are located within a closure:

< some declarations omitted, buildscript, … >

configure(subprojects.findAll { !sourceless.contains( }) {

def platform = platformOf(project)

if (platform == "common") {

    // apply plugin: "kotlin-platform-common"
    // apply plugin: "kotlinx-serialization"
    apply(plugin = "kotlin-platform-common")
    apply(plugin = "kotlinx-serialization")

    dependencies {
        implementation ("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version")
        implementation ("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialization_version")
        testImplementation ("org.jetbrains.kotlin:kotlin-test-common:$kotlin_version")
        testImplementation ("org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version")
    compileKotlinCommon {
        kotlinOptions.freeCompilerArgs += ["-XXLanguage:+InlineClasses", "-Xuse-experimental=kotlin.Experimental"]
    compileTestKotlinCommon {
        kotlinOptions.freeCompilerArgs += ["-XXLanguage:+InlineClasses", "-Xuse-experimental=kotlin.Experimental"]


< some more cases for different project types omitted >


I get the following error:

Could not set unknown property ‘plugin’ for project ‘someproject’ of type org.gradle.api.Project.

What am I doing wrong and how can I fix this.

Thanks in advance for your help.

Replying to my own question.

After much head scratching I found out I was mixing the part of Kotlin DSL migration preparation with the actual migration. What I had to do was transform apply plugin: “someplugin” to apply(plugin: “someplugin”).
Replacing “:” by “=” must only be done during the actual Groovy -> Kotlin migration.