source

abstract fun source(sourceSet: KotlinSourceSet)

Deprecated

scheduled for removal with Kotlin 2.1

Will add a KotlinSourceSet directly into this compilation. This method is deprecated and is soon to be removed.

After this method is removed, there will be exactly one SourceSet associated with a given Kotlin compilation.

To include other sources in the compilation, build a hierarchy of Source Sets instead. See: KotlinSourceSet.dependsOn or KotlinTargetHierarchyDsl. This approach is most applicable if

  • The sources can be shared for multiple compilations

  • The sources shall be analyzed in a different context than defaultSourceSet

  • The project uses multiplatform and sources shall provide expects

Alternatively, when just including source files from another directory, the SourceDirectorySet from the defaultSourceSet can be used. This approach is most applicable if

  • sources are not intended to be shared across multiple compilations

  • sources shall be analyzed in the same context as other sources in the defaultSourceSet

Example 1: Create a new 'utils' source set and make it available to the 'main' compilation:

kotlin {
val compilation = target.compilations.getByName("main")
val utilsSourceSet = sourceSets.create("utils")
compilation.defaultSourceSet.dependsOn(utilsSourceSet)
}

Example 2: Add 'src/utils/kotlin' to the main SourceSet

kotlin {
val compilation = target.compilations.getByName("main")
compilation.defaultSourceSet.kotlin.srcDir("src/utils/kotlin")
}

Further details: https://kotl.in/compilation-source-deprecation