https://kotlinlang.org logo
Title
f

FoRRestDp

05/13/2023, 3:19 PM
How should I set opt-in in a multiplatform project?
sourceSets {
    all { languageSettings.optIn("opt.in.Class") }
    commonMain {
        dependecies {
            implementation("dep.that.require.annotation")
        }
    }

}
If I do it that way I get a warning that
opt.in.Class
is unresolved for some source sets.
sourceSets {
    commonMain {
        languageSettings.optIn("opt.in.Class")
        dependecies {
            implementation("dep.that.require.annotation")
        }
    }

}
If I do it this way I get an error that opt in should be applied to all dependent source sets.
j

Jeff Lockhart

05/15/2023, 10:58 AM
The first way works for me. Which source set does it say it's unresolved for?
f

FoRRestDp

05/15/2023, 11:52 AM
androidMain
. I get the following warning when build project:
> Task :module:compileDebugKotlinAndroid
w: Opt-in requirement marker com.russhwolf.settings.ExperimentalSettingsApi is unresolved. Please make sure it's present in the module dependencies
j

Jeff Lockhart

05/15/2023, 1:44 PM
Seems odd. Have you tried also adding it explicitly to the
androidMain
source set?
f

FoRRestDp

05/15/2023, 1:47 PM
Adding opt-in or dependency on lib?
j

Jeff Lockhart

05/15/2023, 1:54 PM
Opt-in
f

FoRRestDp

05/15/2023, 2:30 PM
That worked. I can’t understand why though. As it seems to me
all { }
should’ve added opt-in to all source sets
j

Jeff Lockhart

05/15/2023, 2:34 PM
I would think so. Maybe file a bug.
f

FoRRestDp

05/15/2023, 2:35 PM
Okay. Thank you for your help!