Skip to content
Advertisement

Execution failed for task ‘:app:compileJava’ with ./gradlew run

When I try using “./gradlew run” on my gradle projects, I receive this error:

* What went wrong:
Execution failed for task ':app:compileJava'.
> java.lang.IllegalAccessError: class org.gradle.internal.compiler.java.ClassNameCollector (in unnamed module @0x1fa4cfc5) cannot access class com.sun.tools.javac.code.Symbol$TypeSymbol (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.code to unnamed module @0x1fa4cfc5

I have tried on multiple different projects and it still doesn’t work. I believe it has something to do with gradle expecting a different version of Java, as I am using java 16 and when I check “gradle -v” it says “JVM: 15.0.2”. I am not sure how to fix this or if this is even the problem. Any help would be greatly appreciated!

Advertisement

Answer

Turns out I had multiple paths for java in my Path system variable. I deleted all but the correct one and then added a JAVA_HOME system variable with a value of the correct path for JDK (C:Program FilesJavajdk-“version”).

Advertisement