Skip to content

[K2] KMP: Support intersecting source roots #3701

@atyrin

Description

@atyrin

Sometimes projects may use the same folder as source root in different modules. Like the same dir for several targets in KMP.
It can be done with such syntax:

kotlin {
  sourceSets {
    jsMain {
      kotlin.srcDir('src/browserMain/kotlin')
    }
    wasmJsMain {
      kotlin.srcDir('src/browserMain/kotlin')
    }
  }
}

Possible scenarios for that: Android and JVM source sets or Js and WasmJs. Sharing source sources for them using KMP hierarchies is just painful.

Projects that already use the pattern:

Kotlin with K2 works fine for them.
IJ with Kotlin K2 Analysis also works: it just uses one of the platforms for analysis. And report warning:

Path [/Users/Andrei.Tyrin/IdeaProjects/_external/molecule/molecule-runtime/src/browserMain/kotlin] of module [molecule.molecule-runtime.jsMain] was removed from modules [molecule.molecule-runtime.wasmJsMain]

Dokka at the same time has the special treatment for that (#3239):

Pre-generation validity check failed: Source sets 'android' and 'jvm' have the common source roots: /Users/Andrei.Tyrin/IdeaProjects/_gates/firebase-kotlin-sdk_mpp/firebase-config/src/androidMain/kotlin. Every Kotlin source file should belong to only one source set (module).

There is a ticket to forbid such setup in KGP: https://youtrack.jetbrains.com/issue/KT-62829/Add-a-check-that-two-source-sets-cannot-have-the-same-file-system-directory. But the priority is low.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked: AAChanges required in Analysis APIbugtopic: K2Issues / PRs that are related to the K2 migration. See #2888upstream bugAn issue that appears due to an upstream dependency bug, such as kotlin-compiler

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions