google-java-format
google-java-format copied to clipboard
organize imports doesnt work for Eclipse Oxygen.3a Release (4.7.3a)
I'm trying to setup google-java-format plugin for eclipse and for intellij so my team can work with different IDEs. However, though it works well for Intellij it doesnt for the mentioned eclipse version. It formats the code but imports arent touched at all.
Just tried the same with Eclipse Neon. Same Problem - imports arent organized. I'm using version 1.6. Is there something missing in the documentation maybe? It only says to
Drop it into the Eclipse drop-ins folder to activate the plugin.
Okay. As described here: https://github.com/google/google-java-format you only have to activate the plugin. For intellij it says you have to load a xml config file also. So i wondered if this is needed for eclipse too. So i tried to load the config file from https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml As it seems it works. So i dont know if the google formatter should work without doing this because for me it didnt.
Just a guess, but maybe it's because formatting happens in https://github.com/google/google-java-format/blob/d109789d7e078a3e81803683727096412f463ba8/core/src/main/java/com/google/googlejavaformat/java/ImportOrderer.java while the plugin may be using just the https://github.com/google/google-java-format/blob/4ae067aef19d0882c5a61f514ea40fa88e9b7067/core/src/main/java/com/google/googlejavaformat/java/SnippetFormatter.java
After a quick look I'm quite convinced that the SnippetFormatter
that Eclipse plugin is using just doesn't organize imports.
To fix my problem with eclipse import organization I had to manually:
- Remove all packages from Java->Appearance->Code Style->Organize Imports
- Create a new "Active profile"
- Set
Between import groups
= 1
For me worked only by removing all packages from the "Organize Imports" section (after adding the google java format plugin -1.6 only, January 2020- and the google style guide xml for eclipse). Hope it works for you.
PD: The only missing part is the line or groups as mentioned in comment above, but order and priority seems ok