Eugene
08/26/2021, 8:48 AMtasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-opt-in=org.mylibrary.OptInAnnotation"
}
Option #2 - using sourceSet
sourceSets {
all {
languageSettings.optIn("org.mylibrary.OptInAnnotation")
}
}
Please vote and leave your WHY in thread. ThanksEugene
08/26/2021, 8:51 AMtask
and how to use it properly.gildor
08/26/2021, 9:14 AMStrum355
08/26/2021, 9:18 AMsourceSets
, I generally think of them as/use them for only handling source locations etc rather than configuring language aspects, but I would prefer to do more than just concating strings for compiler args.
I could understand the second if you wanted to only apply certain language settings to certain sourcesets, but dont have a nice solution in mind to do it another way, nor do I know how common that use case even is, id probably end up making a subproject insteadandylamax
08/26/2021, 9:18 AMgildor
08/26/2021, 9:18 AMgildor
08/26/2021, 9:20 AMJavier
08/26/2021, 10:03 AMEugene
08/26/2021, 10:29 AMmbonnin
08/26/2021, 11:43 AMjvmMain
and commonMain
sourceSets so if I have conflicting compiler options there, I don't know how they're going to be resolved.mbonnin
08/26/2021, 11:43 AMmbonnin
09/03/2021, 4:12 PMmbonnin
09/03/2021, 4:13 PMmbonnin
09/03/2021, 4:15 PMdsavvinov
09/06/2021, 3:13 PMcommonMain
together with jvmMain
. So it might seem that compiler options for commonMain
are redundant and/or unnatural
But then you have an IDE, which does analyze commonMain
on its own. Should usages of OptIn
be allowed there? What if JVM-compilation and JS-compilation declare different sets of OptIns? (or any other compiler options, for that matter)?
(actually, even now we compile common source sets alone into .kotlin_metadata for our internal technical purposes of helping IDE further, but that’s probably can be seen as implementation detail)
Moreover, in future we’d like to turn source sets a proper compilation unit in Kotlin. commonMain
would be compiled into .klib
(pure-Kotlin format of distributing Kotlin code) and then used as a dependency during compilation of jvmMain
. This brings a lot of nice things, like an ability to distribute your pure-Kotlin library as just common-code, leaving consumers ability to link it to any supported platform.
In such future, Kotlin Options will have to be declared on source sets. And as you’ve correctly mentioned, they should obey some consistency rules. For example, it’s obvious that if some language feature, like InlineClasses
is enabled in commonMain
, it can’t be disabled in jvmMain
(how the hell jvmMain
would be supposed to read commonMain.klib
?). Of course, we will make sure that our tooling checks for those rules, points to violations and explains what you should do instead.dsavvinov
09/06/2021, 3:17 PMmbonnin
09/06/2021, 3:21 PMmbonnin
09/06/2021, 3:24 PMkotlin {
languageSettings.optInt += "org.mylibrary.OptInAnnotation"
}
that would this under the hood:
sourceSets.all {
languageSettings.optInt += "org.mylibrary.OptInAnnotation"
}
mbonnin
09/06/2021, 3:27 PMfreeCompilerArgs
) while other seem to wrap them in user-friendly APIs (languageSettings.optIn(...)
). I'd prefer if there'd be only one way to do it. Either string flags or more strongly typed APIs but the mix seems arbitrary theredsavvinov
09/06/2021, 3:37 PMGabriel Ittner
09/06/2021, 5:34 PMdefaultConfig
to set your general options and then you can override that in specific flavors/buildTypes/variants if needed.