0

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

Dude2345
  • 57
  • 8
  • Several preview features are in JDK 17 not preview anymore. Try to use 17... – 30thh Oct 01 '21 at 04:09
  • 1
    @30thh That won't work, the problem is the library the OP is using, which was compiled for Java 16 with preview features enabled. This means it can only be used on Java 16 with preview features enabled, and not on any other Java version. – Mark Rotteveel Oct 01 '21 at 11:08
  • 1
    If you're still running Java 16, you probably need to enable preview features in your Gradle build file. For example, see [How to enable Java 12 preview features with Gradle?](https://stackoverflow.com/questions/55433883/how-to-enable-java-12-preview-features-with-gradle) – Mark Rotteveel Oct 01 '21 at 11:11
  • Yep that worked thanks! – Dude2345 Oct 01 '21 at 15:45

1 Answers1

0

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'
}
Dude2345
  • 57
  • 8