skip to Main Content

I’m currently working on a Java project where multiple developers are using different code editors. Some use VSCode while others use IntelliJ. I have been looking into a way for all devs to use the same code style config without any luck.
I have tried to use .editorconfig (works in VSCode with extention. IntelliJ has native support)

Tried using the Google Java Code Style XML. (works in VSCode with extention. IntelliJ has native support)
(https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml)

Every solution results in VSCode not formatting a particular file the same way IntelliJ does.

A quick google search did not help.

How can I, as a Java developer, manage code style in large projects where multiple devs use a variety of code editors?

2

Answers


  1. EditorConfig

    As marstran noted in a comment, EditorConfig is an attempt at standardizing those settings.

    • IntelliJ supports EditorConfig; see this page.
    • VisualStudio supports EditorConfig.
    • VisualStudio Code supports EditorConfig through a plug-in.
    Login or Signup to reply.
  2. It seems as though the answer is "no" depending on the IDEs that your team uses.

    The TLDR; is that both VSCode and Intellij interpret Eclipse based style xml files differently.

    I dug into this today and it seems that the root of the problem is how various IDEs interpret the rules defined in the xml style guides. I tried the following with VSCode, IntelliJ Ultimate Edition, and Eclipse (all of which were the latest versions as of the writing of this post):

    • Configured VSCode to use the Google style guide by adding the following to the user’s settings.json
      "java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
      
    • Imported the same style guide into Intellij
    • Imported the same style guide into Eclipse
    • For each IDE, took a sample Java class and reformatted the code

    Both Eclipse and VSCode reformatted the code exactly the same way. Intellij interpreted the xml style differently resulting in the following. VSCode formatting is on the left and Intellij is on the right.

    enter image description here

    It seems that without digging through the Intellij source code and applying changes such that it will then interpret the style xml the same as the other IDEs then there is not going to be an easy way to ensure that these two IDEs (and perhaps others) apply code formatting in exactly the same way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search