When I tried to build my Java code which has switch expressions using Gradle, it throws this error:
error: switch expressions are a preview feature and are disabled by default.
I tried running ./gradlew build --enable-preview
which didn't work either.
I'm using Gradle 5.3.1.
First, you need to go preference, and then Build, Execution, Deployment and then Select Java Compiler. And then go to the run configuration. Select the modify options and Mark the Add VM options. You need to add --enable-preview there as well.
The minimum version of Gradle that supports Java 11 is 5.0 . You would need to upgrade to version 7.0 or above for Android.
You need to configure the JavaCompile
tasks, so that Gradle passes this option to the Java compiler when compiling.
Something like this should work:
tasks.withType(JavaCompile).each { it.options.compilerArgs.add('--enable-preview') }
To run the app/tests we need to add jvmArgs
.
Example:
test { jvmArgs(['--enable-preview']) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With