What's the proper way to pass the `-Xexpect-actual-classes` flag to the compiler in 1.9.20-RC? Previ...
j
What's the proper way to pass the
-Xexpect-actual-classes
flag to the compiler in 1.9.20-RC? Previously in 1.9.20-Beta2 I had:
Copy code
kotlin {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
But this top-level
compilerOptions
has been removed now. I've tried
Copy code
tasks.withType<KotlinCompile>().configureEach {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
and
Copy code
tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        freeCompilerArgs += "-Xexpect-actual-classes"
    }
}
but still get the warning
'expect'/'actual' classes (including interfaces, objects, annotations, enums, and 'actual' typealiases) are in Beta. You can use -Xexpect-actual-classes flag to suppress this warning. Also see: https://youtrack.jetbrains.com/issue/KT-61573
during compilation.
youtrack 1
Also doesn't work:
Copy code
tasks.withType<KotlinCompilationTask<*>>().configureEach {
    compilerOptions {
        freeCompilerArgs.add("-Xexpect-actual-classes")
    }
}
a
Indeed, we decided to take more time to polish the top-level
compilerOptions
and it’s now postponed until 2.0 Please try using
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.add("-Xexpect-actual-classes")
            }
        }
    }
}
j
Thanks, this looks to work. What's the reason the other mechanisms to pass
freeCompilerArgs
don't work?
a
Did you see compilation errors (from Gradle) or red code in IDEA?
j
I see both Gradle compilation warnings and warnings in the IDE (not errors or red code, just warnings) using the mechanisms I tried. Both warnings go away with your method.
a
How can I fix it with Groovy Gradle and Kotlin 1.9.20?
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.add("-Xexpect-actual-classes")
            }
        }
    }
}
Gives:
Copy code
> Ambiguous method overloading for method org.jetbrains.kotlin.gradle.targets.native.NativeCompilerOptions#configure.
  Cannot resolve which method to invoke for [class build_a61yfy2uoq4qbs0ma6w75b74a$_run_closure2$_closure4$_closure7$_closure8] due to overlapping prototypes between:
  	[interface kotlin.jvm.functions.Function1]
  	[interface org.gradle.api.Action]
This seems working.
Copy code
kotlin {
    targets.configureEach {
        compilations.configureEach {
            compilerOptions.configure((Action) { it.freeCompilerArgs.add("-Xexpect-actual-classes") })
        }
    }
}
e
is this supposed to work in KMP as well? Because for my generated code it doesnt look working..
Copy code
kotlin {
    targets.all {
        compilations.all {
            compilerOptions.configure {
                freeCompilerArgs.addAll("-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn", "-Xexpect-actual-classes")
            }
        }
    }
}
a
Yep, the expect/actual flag works for me with KMP. I replaced
all
with
configureEach
, though.
e
Copy code
targets.configureEach {
    compilations.configureEach {
        compilerOptions.configure {
            freeCompilerArgs.addAll("-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn", "-Xexpect-actual-classes")
        }
    }
}
same results
and this
(Action) { it.freeCompilerArgs
doesn't even compile (kts)
a
The thing with Action was needed for Groovy. For Kts the last code I posted works for me.
1319 Views