google-java-format-gradle-plugin
google-java-format-gradle-plugin copied to clipboard
False claim of syntax error
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.
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
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.
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 like1.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).
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?
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'
}
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.