Following an earlier comment on this channel, usin...
# announcements
k
Following an earlier comment on this channel, using this Gradle Kotlin DSL to enable language flags seem to be working fine. However, there’s no documentation or a mention of it anywhere, regarding whether/not it’s a stable API that should/not be used. I’m curious if this is indeed a recommended solution
Copy code
subprojects {
    afterEvaluate {
        the<KotlinProjectExtension>().sourceSets.all {
            languageSettings(closureOf<LanguageSettingsBuilder> {
                progressiveMode = true
                enableLanguageFeature("NewInference")
                enableLanguageFeature("InlineClasses")
                ...

                useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
            })
        }
    }
}
d
Is this an option you're using in favor of
tasks.withType<KotlinCompile> { freeCompilerArgs = listOf("-XXLanguage:+NewInference") }
? (Sorry I only use kotlin Gradle dsl)
1
k
Yes. This snippet is also using the Kotlin DSL
d
My phone did some weird autocorrecting there.
k
Hehe. No worries 🙂
d
It seems like you need a lot of boilerplate to do it that way
Im going to guess that's something they'd want to do better.
k
Not really. This is applying it across all subprojects. For a single module. I could easily do something like:
Copy code
kotlin.sourceSets.all {
    languageSettings(closureOf<LanguageSettingsBuilder> {
        progressiveMode = true
        listOf("NewInference", "InlineClasses").forEach(::enableLanguageFeature)
    })
}
Seems much cleaner and intentional than passing raw flags
With your example, this is equivalent to:
Copy code
tasks.withType<KotlinCompile> {
    freeCompilerArgs += listOf(
            "-progressive",
            "-XXLanguage:+NewInference",
            "-XXLanguage:+InlineClasses"
    )
}
d
Which you can wrap in a
subprojects
block?
k
Yes, I believe