UnsupportedClassVersionError : Error with Gradle and Java Runtime version
Asked Answered
S

2

7

I'm very new to Gradle, and I wanted to give a try to this cool project : Strange, a Quantum Computing API for Java (I'll leave a link to the github project below). They recommend using Gradle, so I did.

In the directory I'm working on, there's only 3 files :

  1. My java main class HelloStrangeWorld.java,
  2. build.gradle,
  3. and settings.gradle

Now I just wanted to test, in my directory, the command :

$ gradle tasks

And I got this :

FAILURE: Build failed with an exception. * What went wrong: java.lang.UnsupportedClassVersionError: org/javamodularity/moduleplugin/ModuleSystemPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

org/javamodularity/moduleplugin/ModuleSystemPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0


What I have :

  • My Java is set on 1.8

  • I installed Graddle using SDKMAN

The content of build.gradle is the following :

plugins {
    id 'java'
    id 'application'
    id 'org.javamodularity.moduleplugin' version '1.2.1'
}

group 'helloStrangeWorld'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.gluonhq:strange:0.0.5'
}

mainClassName = 'HelloStrangeWorld'

The content of my main class is the following :

import com.gluonhq.strange.*;
import com.gluonhq.strange.gate.*;
import com.gluonhq.strange.local.SimpleQuantumExecutionEnvironment;
import java.util.Arrays;

public class HelloStrangeWorld {

    public static void main(String[] args) {
        Program p = new Program(2);
        Step s = new Step();
        s.addGate(new X(0));
        p.addStep(s);
        Step t = new Step();
        t.addGate(new Hadamard(0));
        t.addGate(new X(1));
        p.addStep(t);
        SimpleQuantumExecutionEnvironment sqee = new SimpleQuantumExecutionEnvironment();
        Result res = sqee.runProgram(p);
        Qubit[] qubits = res.getQubits();
        Arrays.asList(qubits).forEach(q -> System.out.println("qubit with probability on 1 = "+q.getProbability()+", measured it gives "+ q.measure()));
    }

}

What I've tried so far :

  • I have checked that my JAVA_HOME is setted to my jdk8. I use zsh, so I checked on both .bashrc and .zshrc, and the env variable is setted in both place.

  • I changed from Java 8 to Java 7, it returns me that Gradle isn't supposed to work with Java 7. So I went back to Java 8

  • I checked the symbolic links setted in /etc/alternatives and all the java related are pointing to the version 8 of java

Am I missing something obvious about the use of Gradle ?

Thank you

Here's the link for the Strange project on gitHub.

Sigmund answered 11/1, 2019 at 9:52 Comment(1)
Related, possibly duplicate: #10383429Roid
L
10

Java 8 doesn't support quantum computing. You need Java 11 or later.

Jokes aside, the project you're including depends on OpenJFX 11-ea+24, which requires Java 11.

Get OpenJDK 11 here.

Note: UnsupportedClassVersionError prints a number like 55.0. Subtract 44 from it to determine the needed Java version.

Lemaceon answered 11/1, 2019 at 9:59 Comment(2)
Thank you for this useful tip !Sigmund
"Java 8 doesn't support quantum computing." lolololUnlimber
N
1

Last week, I updated my Mac's Android Studio from 2021.2.1 to 2021.3.1. Then our project was built failed for the similar reason:

Cause: com/android/tools/idea/gradle/run/OutputBuildAction has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 53.0

I found several discussion on the Jetbrains YouTrack Forum: Failed to run Android project in the Idea 2020.3 EAP (OutputBuildAction has been compiled by a more recent version of the Java Runtime (class file version 55.0)). The suggested workaround is to update the defined Gradle JDK version to JDK11, but many Android projects don't support Gradle JDK11, so does mine.

Another solution is to downgrade Android Studio from 2021.3.1 to 2021.2.1, and it worked for me. Hope it helps.

Niven answered 24/10, 2022 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.