How to add a sourceset inside a plugin

Hi guys, my plugin generates some Kotlin code, and puts into “build/generated/source/plugged/main/kotlin”.
I just wanted to understand how can I add this path as a source directory for Kotlin?
I tried to use:

open class MyPlugin : Plugin<Project> {
    override fun apply(target: Project) {
            val sourceSets = target.properties["sourceSets"] as SourceSetContainer
            sourceSets.getByName("main").allSource.srcDirs.add(File(destination))
    }
}

but it doesn’t seem to work