google-java-format-gradle-plugin icon indicating copy to clipboard operation
google-java-format-gradle-plugin copied to clipboard

False claim of syntax error

Open Bios-Marcel opened this issue 4 years ago • 6 comments

The plugin claims a syntax error, even though the task compileJava runs just fine. There's absolutely no syntax error in any of the files. I've also tried running the clean task. I really don't know what's going on. It worked and at some point just stopped working.

> Task :client:googleJavaFormat FAILED


Detected Java syntax errors in the following files (you can exclude them from this task, see "https://github.com/sherter/google-java-format-gradle-plugin" for details):

D:\repos\demo\client\src\main\java\com\isp\kkg\client\Client.java
D:\repos\demo\client\src\main\java\com\isp\kkg\client\ClientHello.java
D:\repos\demo\client\src\test\java\com\isp\kkg\client\DummyTest.java

Is there anything else I can give you? I can even send you the project as a zip if you want. It's just a demo anyways.

Bios-Marcel avatar Oct 18 '21 16:10 Bios-Marcel

I uploaded the demo I am using. I tried it on another machine and it worked. So something might be going on with caching or so?

https://github.com/Bios-Marcel/gradle-multi-project-demo

Bios-Marcel avatar Oct 19 '21 08:10 Bios-Marcel

I'm also seeing this after upgrading from 0.8 to 0.9. I've updated Gradle and the JDK at the same time, so there could be other things at play too.

edsrzf avatar Oct 22 '21 02:10 edsrzf

I had this same error after updating to JDK 17 and Gradle 7.2. I found two errors that may cause this message:

  • One happens if you are using an old version of google-java-formatter, which does not support Java 17. Make sure to use a recent version like 1.12.0.
  • The other happens because enabling internal JDK modules are required to run on JDK 17. I posted a fix for this here: https://github.com/sherter/google-java-format-gradle-plugin/issues/67#issuecomment-945845219.

I also opened PR #66 to provide a better error message, but unfortunately, the project seems to be unmaintained currently (#57).

aecio avatar Oct 23 '21 23:10 aecio

I have the same problem, with Java 14 source compatibility and Gradle 7.2

One happens if you are using an old version of google-java-formatter, which does not support Java 17. Make sure to use a recent version like 1.12.0.

@aecio: where do I set this? This is an intellij plugin right? Isn't that different from the gradle plugin we discuss here?

cies avatar Jan 27 '22 16:01 cies

This Gradle plugin is a wrapper for the original Google's library google-java-formatter. As described in the README of this project, you can change the library version by adding the following configuration in your Gradle build file:

googleJavaFormat {
  toolVersion = '1.1-SNAPSHOT'
}

aecio avatar Jan 27 '22 21:01 aecio

One more hint for those who try to fix this issue:

Make sure your gradlew uses the right JDK version. I had this problem when using the latest plugin version with the latest toolVersion specified in the gradle file with the flags as specified in #67 ... Still it did not work because my gradlew used my system default JDK11.

I fixed it with:

mkdir -p $HOME/.gradle
echo "org.gradle.java.home=$HOME/.jdks/temurin-17.xyz/" > $HOME/.gradle/gradle.properties

Where $HOME/.jdks/temurin-17.xyz/ should be replaced with the path to right JDK.

cies avatar Sep 04 '22 19:09 cies