There is ```kotlin { sourceSets.configureEach { ...
# gradle
c
There is
Copy code
kotlin {
	sourceSets.configureEach {
		languageSettings {
			enableLanguageFeature("context-parameters")
		}
	}
}
and
Copy code
kotlin {
	compilerOptions {
		freeCompilerArgs.add("-Xcontext-parameters")
	}
}
Which is more idiomatic? • Only the second one gets recognized up by IntelliJ • However,
enableLanguageFeature
seems clearer than
freeCompilerArgs
j
The IDE recognizes:
Copy code
languageSettings.enableLanguageFeature("ContextParameters")
For me at least
As for which one to use... I have no idea. I think most official documentation mentions the compiler parameter. I kind of like the language feature since it feels more idiomatic. I wish there was like an Enum of features supported or something though, sometimes it's hard to know the exact string to use!
➕ 4
z
IDE works fine for the freeCompilerArgs approach too, they end up in the same place
j
Copy code
kotlin {
	sourceSets.configureEach {
		languageSettings {
			enableLanguageFeature(LanguageFeature.ContextParameters.name)
		}
	}
}
🙌 1
Sadly, it is going to be removed 😞 IMO it should not only be saved, but remove accepting a String so you can just
Copy code
enableLanguageFeature(LanguageFeature.ContextParameters)
c
🤔 For me in 2026.1 EAP, the
sourceSets.configureEach {}
approach compiles correctly from the CLI, but the IDE complains that context parameters are not enabled.
t
note that
enableLanguageFeatures
API is deprecated in Kotlin 2.3.20 release. This API uses Kotlin compiler internal flags which is not intended by used by users. Also, in general,
languageSettings
API is soft-deprecated in favor of
kotlin.compilerOptions
DSL.
🤔 1
j
@tapchicoma I still think that movement does not make sense if we do not get something like
Copy code
kotlin.compilerOptions.languageFeatures(listOf(LanguageFeature.ContextParameters, ...))

// or only for experimental "public" features
kotlin.compilerOptions.experimentalFeatures(listOf(ExperimentalFeature.ContextParameters, ...))
Adding complexity to try new features is just make users angry. I do not ever know how many times I have looked at Google to add
"-Xcontext-parameters"
because I forgot if it was with
-
, or
_
, if it is
-X
, etc.
t
we want to expose
-X
arguments in the DSL: KT-61035 Expose experimental compiler arguments in the Gradle DSL The problem is that currently
-X
arguments are a mix of everything making it hard to design a proper DSL. For example, not everything in
-X
is experimental which could be removed/changed in any Kotlin release. We are working on this and hopefully this year we will address it.
👍 1
thank you color 2