Hello all, I have a gradle question regarding kotl...
# multiplatform
k
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
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
cool thanks! So is
by getting
the recommended approach for multiplatform sourcesets?
a
no problem! I’m not sure if
by getting
is recommended per se, but it’s certainly more common in the documentation
j
It doesn't matter. It's more your level of tolerance for the extreme cuteness of the Kotlin DSL or not