1

I have OpenJDK 19 installed and use the "google-java-format" plugin. I have configured IntelliJ IDEA as per instructions here. However, code formatting doesn't work.

If I uninstall the plugin, formatting works (i.e. the cmd-opt-L shortcut works). But when I enable the plugin, then the cmd-opt-L shortcut doesn't work and inserted code fragments look crap.

Also, the notifications window always reminds me to configure the IDE properly, following the instructions above. Well, I did configure the IDE accordingly. Still I see the notifications and formatting doesn't work.

What could be wrong?

Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45
  • I don't know if it's been fixed, but I noticed the google-java-format IntelliJ plugin broke if I used any of the new Java language features (e.g., switch expressions, records, pattern matching, etc.). It even used to break on `module-info.java` (I believe that's been fixed for a while, at least). Lately I've been using Gradle plugins (e.g., Spotless) to auto-format code. It might be possible to use "google-java-format" that way, though I haven't tried it in a while as I prefer "palantir-java-format". – Slaw Mar 12 '23 at 21:35
  • 1
    You may report this issue to google-java-format issue tracker. Also, you could try the google-java-format CLI tool to see if it can reformat your code. If it doesn't work, it may doesn't support these new features otherwise it would be a google-java-format IntelliJ plugin issue. – LJ replica Mar 13 '23 at 04:31

1 Answers1

2

It seems like I didn't copy all configs correctly; not sure what exactly was missing, but I think it was --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED ; probably that wasn't needed in earlier versions of the plugin?

--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45