google / google-java-format

Reformats Java source code to comply with Google Java Style.
Other
5.64k stars 856 forks source link

in idea 2022.3.3, this plugin throw error : configure the jre for google-java-format #940

Open git-code-for-me opened 1 year ago

git-code-for-me commented 1 year ago

the configure is not work, in idea 2022.3.3

--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

--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED

--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

andskiba commented 1 year ago

@git-code-for-me I had the exact same problem today. Apparently it's very important that you put a newline at the end of you .vmoptions file otherwise the last option gets concatenated with some other options that idea is adding.

malopez16 commented 1 year ago

adding new line doesn't work for me.

evilmilo commented 1 year ago

I've having same issue, idea 2023.2.4 Running on intel mac. openjdk version "17.0.9" 2023-10-17

Keep getting the popup every time start IDE saying to configure the jre for google-java-format

Formatting doesn't work at all. The preview window in Code Style doesn't update with config changes.

Checked idea.log , and can't see anything to explain why this isn't loading, not errors or warning, just single line saying loaded plugin:

2023-11-02 08:56:58,416 [ 241] INFO - #c.i.i.p.PluginManager - Loaded custom plugins: google-java-format (1.17.0.0), Save Actions - XDEV Edition (1.0.4)

idea.vmoptions

-Xmx2048m
--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

Is there anywhere else to get logs or diagnostics on why this plugin isn't loading properly?

plumpy commented 1 year ago

Can you see if those options are actually being applied to the JVM? For example, if you do a ps auxw | grep idea.Main, do you see those options (all six of them) being passed to the JVM?

(Sorry, I don't have a Mac, so I don't know if ps auxw actually works there, but I think it should...)

evilmilo commented 1 year ago
% ps auxw | grep idea.Main
nathan.mcdonald  25041   0.5  0.0 34130588    740 s009  S+    2:01pm   0:00.01 grep idea.Main
evilmilo commented 1 year ago

So looks like issue with intellij on mac, not the plugin (not picking up vm options).

Instead, I editted: /Applications/IntelliJ\ IDEA\ CE.app/Contents/Info.plist

Found this section:

<key>JVMVersion</key>
      <string>1.8*,1.8+</string>
      <key>MainClass</key>
      <string>com/intellij/idea/Main</string>
      <key>ErrorFile</key>
      <string>-XX:ErrorFile=$USER_HOME/java_error_in_idea_%p.log</string>
      <key>HeapDump</key>
      <string>-XX:HeapDumpPath=$USER_HOME/java_error_in_idea.hprof</string>
      <key>Options</key>
      <array>
        <string>--add-opens=java.base/java.io=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.lang=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.lang.ref=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.lang.reflect=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.net=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.nio=ALL-UNNAMED</string>
        <string>--add-opens=java.base/java.nio.charset=ALL-UNNAMED</string>
       ....

and at the end of that array, added the other strings

        <string>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</string>
        <string>--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</string>
        <string>--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</string>
        <string>--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</string>

Restarted, and now works as expected!

evilmilo commented 1 year ago

Hmm... so raised with Intellij, but they said vm options are loading correctly, so maybe issue with plugin not picking up options correctly?

https://youtrack.jetbrains.com/issue/IDEA-337068/Custom-VM-Options...-are-not-being-applied-when-running-on-Mac