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 :
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
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()));
}
}
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.
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.