https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Kevin S

03/16/2023, 4:59 PM
Hello all, I have a gradle question regarding kotlin sourceSets. I normally see definitions like
val commonMain by getting
, but in a compose template they’ve used
named("commonMain")
. Is one method preferred over the other? I notice that with the first approach, there is an
UNUSED_VARIABLE
warning, is that a reason to not use by getting?
a

Adam S

03/16/2023, 5:10 PM
they are equivalent. https://docs.gradle.org/current/userguide/kotlin_dsl.html#using_kotlin_delegated_properties If the source set is created outside of the build script you are configuring you can also use the generated Kotlin DSL accessor
Copy code
kotlin {
  sourceSets {
    commonMain { // generated DSL accessor
    } 
  } 
}
It can be convenient to use the delegated property when you want to re-use the variable, for example, creating a hierarchy
Copy code
sourceSets {
         val commonMain by getting {}
         val commonTest by getting {}

         val nativeMain by creating { dependsOn(commonMain) }
         val nativeTest by creating { dependsOn(commonTest) }
But yes, the ‘unused variable’ warning is annoying
k

Kevin S

03/16/2023, 5:16 PM
cool thanks! So is
by getting
the recommended approach for multiplatform sourcesets?
a

Adam S

03/16/2023, 5:17 PM
no problem! I’m not sure if
by getting
is recommended per se, but it’s certainly more common in the documentation
j

jw

03/16/2023, 5:17 PM
It doesn't matter. It's more your level of tolerance for the extreme cuteness of the Kotlin DSL or not
11 Views