WhatsApp4j - Api | Does not compile because class uses preview features

554 views Asked by At

I wanted to try out the (https://github.com/Auties00/WhatsappWeb4j) Whatsapp4j library, my gradle:

        plugins {
        id 'java'
    }
    
    group 'de.test'
    version '1.0-SNAPSHOT'
    
    repositories {
        mavenCentral()
    }

dependencies {
    implementation 'com.github.auties00:whatsappweb4j:2.2.1'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}

I only added it to my gradle file, and when I run my Main.java (which only implements an class of this library)

  import it.auties.whatsapp4j.whatsapp.WhatsappAPI;
    
    public class Main {
    
        public static void main(String[] args) {
        }
    }

I receive this error:

error: classfile for
C:\Users\User\.gradle\caches\modules-2\files-2.1\com.github.auties00\whatsappweb4j\2.2.1b3c7842cc489e3ae0cc6147c84b11ff6334671e\whatsappweb4j-2.2.1.jar(/it/auties/whatsapp4j/whatsapp/WhatsappAPI.class)
uses preview features of Java SE 16.

I tried to fix it setting my language level to preview (I don't rly know what preview features are) : https://prnt.sc/1uaay97 but sadly that didn't work. The error remained. I hope someone knows how to fix it.

-I use IntelliJ IDEA

1

There are 1 answers

0
Dude2345 On BEST ANSWER

As @Mark Rotteveel pointed out enabling preview features in the Gradle build file worked.

How to enable Java 12 preview features with Gradle?

adding this works.

tasks.withType(JavaCompile) {
    options.compilerArgs += "--enable-preview"
}

tasks.withType(Test) {
    jvmArgs += "--enable-preview"
}

tasks.withType(JavaExec) {
    jvmArgs += '--enable-preview'
}