Gradle-Plugin: Get SourceSets of Koltin Multiplatform project


I want to write a Gradle plugin that need to access the source sets.

In a normal Kotlin-JVM project, I can get the sourceSets during task execution in the following way:

val sourceSets =["sourceSets"] as SourceSetContainer

This gives me “main” and “test” source sets.

But in a Koltin Multiplatform project, the sourceSets field is empty during task execution.

Is there another way to get the source sets of the Koltin Multiplatform plugin? Or do I need to respect some special contains?


In Kotlin Multiplatform plugin, the sourceSets container is a part of the kotlin project extension. So you need to get the extension first:

val kotlinExtension = project.extensions.getByName("kotlin") as KotlinMultiplatformExtension
val kotlinSourceSets = kotlinExtension.sourceSets


thanks for the hint.

But I have another problem: KotlinMultiplatformExtension cannot be resolved.

I see it here:

But I cannot find which artifact I have to add to the dependencies of my plugin project.

OK, I have found it:


Now it works. Thank you!