https://kotlinlang.org logo
Title
k

kingsley

11/03/2018, 4:35 PM
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
subprojects {
    afterEvaluate {
        the<KotlinProjectExtension>().sourceSets.all {
            languageSettings(closureOf<LanguageSettingsBuilder> {
                progressiveMode = true
                enableLanguageFeature("NewInference")
                enableLanguageFeature("InlineClasses")
                ...

                useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
            })
        }
    }
}
d

Dico

11/03/2018, 4:40 PM
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

kingsley

11/03/2018, 4:40 PM
Yes. This snippet is also using the Kotlin DSL
d

Dico

11/03/2018, 4:41 PM
My phone did some weird autocorrecting there.
k

kingsley

11/03/2018, 4:41 PM
Hehe. No worries 🙂
d

Dico

11/03/2018, 4:42 PM
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

kingsley

11/03/2018, 4:46 PM
Not really. This is applying it across all subprojects. For a single module. I could easily do something like:
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:
tasks.withType<KotlinCompile> {
    freeCompilerArgs += listOf(
            "-progressive",
            "-XXLanguage:+NewInference",
            "-XXLanguage:+InlineClasses"
    )
}
d

Dico

11/06/2018, 3:09 PM
Which you can wrap in a
subprojects
block?
k

kingsley

11/06/2018, 3:20 PM
Yes, I believe