How to make VS Code organize Java imports like IntelliJ

I’m using VS Code for Java development and working with other developers who use IntelliJ. I’d like to use the Organize Imports command (Shift+Alt+O) to clean up my imports, but I don’t want to fight over import order with every commit. So I’d like to configure VS Code to organize the imports in the same order as IntelliJ’s default. Does anybody have a configuration that would do this?

If this is not possible, is there a workspace configuration I can apply to both VS Code and IntelliJ so that the two IDEs will agree, even if they aren’t agreeing on IntelliJ’s default?

Answer

We were able to get it the almost identical with the following config tweaks.

VS Code:

{
  "java.completion.importOrder": [
    "",
    "javax",
    "java",
    "#"
  ]
}

IntelliJ IntelliJ import order

The only difference from the IntelliJ default is a new line between import javax... and import java....

Leave a Reply

Your email address will not be published. Required fields are marked *