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
EditorConfig
As marstran noted in a comment, EditorConfig is an attempt at standardizing those settings.
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):
settings.json
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.
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.