0

I am working on a java project with a team. All of the members use eclipse and I use intellij. Everytime I push my code to github there are hundreds of diff lines unnecessarily due to formatting differences in eclipse and github. Also hashcode and equals method generate different code style in intellij wrt eclipse.

How can I configure intellij to use same code formatting and code generation style used by eclipse? My teammates use default settings of eclipse.

Karan Bansal
  • 1,314
  • 1
  • 11
  • 16
  • Google for IntelliJ code style templates (e.g. [this](https://www.jetbrains.com/help/idea/configuring-code-style.html)). Basically, you should only need to sync up with what the Eclipse guys are doing to avoid all this. Another option, though less robust, would be to just tell IntelliJ not to apply any template at all, and just accept the Eclipse version of each file. – Tim Biegeleisen Aug 01 '18 at 02:10
  • Any idea how can I do this sync up with eclipse guys. They are using default settings. I searched internet but couldn't find any template for code generation which is used by eclipse default. – Karan Bansal Aug 01 '18 at 02:12
  • There is [Eclipse Code Formatter](https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter) plugin you can try. Also it is possible to change or [create](https://www.jetbrains.com/help/idea/generating-code.html#customize-templates) your own [generate templates](https://www.jetbrains.com/help/idea/using-file-and-code-templates.html) for getters/setters/`hashCode()`/`equals()`. E.g. see this answer: https://stackoverflow.com/a/29256901/2000323. Though I'm not aware of such existing template for the Eclipse-way. – Andrey Aug 01 '18 at 08:49
  • @Andrey I have checked out the links already. All I'm asking for is the default template used by Eclipse. I'm not able to find it yet. – Karan Bansal Aug 01 '18 at 08:54
  • There is no default template. You have to turn to a running eclipse and **export** the current settings. As my answer suggests. So please A) let me know if something is missing from my answer and otherwise B) consider accepting at some point. – GhostCat Aug 01 '18 at 09:36

1 Answers1

1

In eclipse, you can export the code formatter settings to XML.

Intellij allows you to import these settings. That works for most parts. But even on the intellij help pages you find information that some things won't work (but there is an intellij plugin supposed to help, too). See their blog for example.

For code generation, things are a bit different. But I think that intellij even asks you what "style" to use when generating these methods.

The other part that really requires attention: order of import statements. But that one is easily, as that link implies, you edit your IntelliJ settings once, and they match. For the formatter, theoretically, every time when eclipse releases a new release, you might have to export/import settings again. This is a never ending story ...

Leading to: be aware that fighting tooling is always an uphill battle. In our setup, enough people switched from eclipse to intellij to make it work. I wouldn't have made that step otherwise. And I researched such questions first, instead of first learning a new tool, ending up in large, annoying diffs.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • This is exactly the solution,Also on a side note include eclipse .project files and .idea files from intellij in gitignore. Intellij allows you to import all eclipse settings and shortcuts, so you can seamlessly switch ide for application – Pavan Kate Aug 01 '18 at 09:44