error: invalid source release 14 with --enable-preview

10.3k views Asked by At

I am using Micronaut2.0.2 application with IntelliJ IDE 2020.2.2. I have enabled the preview feature in from the language level in IDE

enter image description here

And in the Gradle file I have the below option

java {
    sourceCompatibility = JavaVersion.toVersion('14')
    targetCompatibility = JavaVersion.toVersion('14')
}

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
    options.compilerArgs.addAll([
            '-parameters',
            // enables incremental compilation
            '-Amicronaut.processing.incremental=true',
            '-Amicronaut.processing.annotations=fete.bird.*',
            "-Amicronaut.processing.group=$project.group",
            "-Amicronaut.processing.module=$project.name",
            "--enable-preview"
    ])
}

Getting an error as error: invalid source release 14 with --enable-preview

2

There are 2 answers

4
Andrey On

Set Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Gradle JVM to 14 JDK version.

0
Kidus Tekeste On

If you have some wrong configurations in your pom.xml like this remove it. It worked for me after I remove the configs:

    <configuration>
        <source>15</source>
        <target>15</target>
        <compilerArgs>--enable-preview</compilerArgs>
    </configuration>

That's what was messing up for me. Since I already have Java 16 already.