Hi :open_hands:! Need help with KMM SourceSets I want to add configuration to the compile classpath...
a
Hi 👐! Need help with KMM SourceSets I want to add configuration to the compile classpath of jvmMain. Previously for standard java source sets (main and test sourceSets) my code looked like this:
Copy code
val sourceSets = project.extensions.getByType(JavaPluginExtension::class.java).sourceSets

val configAction: SourceSet.() -> Unit= {
  compileClasspath += myConfiguration
}
          
sourceSets.findByName(name)?.apply(configAction) ?: sourceSets.whenObjectAdded { obj -> if (obj.name == name) configAction.invoke(obj) }
How can I replicate this for KMM-sourceSets? I tried using KotlinMultiplatformExtension, but KotlinSourceSets won't let me add my configuration to the classpath Thanks!
🙋‍♂️ 1
i
In a multiplatform project, a Kotlin source set doesn't have the designated
compileClasspath
configuration which is resolved to determine compilation dependencies because a source set can participate in multiple compilations. But
jvmMain
source set usually participates only in one compilation. You can access that compilation and get its
compileDependencyConfiguration
configuration:
Copy code
kotlin {
     jvm {
           compilations {
                val main by getting {
                     configurations.compileDependencyConfiguration += ...
                }
However, each source set has configurations where it can declare dependencies. You can get the name of the corresponding configuration using source set
...ConfigurationName
properties:
Copy code
kotlin {
     sourceSets {
        val jvmMain by getting {
            project.configurations[compileOnlyConfigurationName] += 
        }
a
Hi! Yes, thank you, that helped! However, in Android Studio (2022.3.1, KMM plugin 0.6.1(223)-18) dependencies are not sync'd and are displayed in red 😭. The build succeeds