0

I work on a Java project using Eclipse and I am deciding which files I should ignore when pushing code to the git repository. Is it a good practice to ignore .project? If it is, would that cause problems if I use different versions of Eclipse to build and import the project?

  • 1
    even worse: some editor-specific files contain absolute paths which will likely not work on someone else's machine. So yes, always ignore these files in git/svn/... – f1sh Apr 29 '21 at 20:02
  • The same question has already been closed as duplicate and then deleted by the author: https://stackoverflow.com/q/67319674/6505250 – howlger Apr 29 '21 at 22:55
  • @f1sh The `.project` file is project-specific, not editor-specific and does not contain absolute paths. It is intended to be shared. So always share the `.project` file. – howlger Apr 29 '21 at 23:45

1 Answers1

5

Yes, you should ignore .project and .eclipse metadata and any other editor specific metadata and use a system like gradle or maven to structure and build your project - that way editors or their versions used should not matter.

For sharing editor configurations with different editors, you can use .editorconfig files.

eis
  • 51,991
  • 13
  • 150
  • 199
  • Perfect, I will learn more about .editorconfig files. Thank you for sharing this information But I still having one question: Do .project file have any relation with the version of Eclipse? – khadija zekraoui Apr 29 '21 at 20:06
  • @khadijazekraoui it's a file definition that of course evolves as eclipse evolves. you can check out it's changes in its [change history](https://github.com/eclipse/eclipse.platform.resources/commits/master/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/IProjectDescription.java) – eis Apr 29 '21 at 20:27
  • @khadijazekraoui if you feel your question has been answered, remember to [accept an answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – eis Apr 29 '21 at 20:35
  • @eis That's not true. The `.project` file is version independent and unrelated to Gradle, Maven and editorconfig. According to the Eclipse documentation it should be shared. – howlger Apr 29 '21 at 23:05
  • @eis The change history you refer to is not the file format of the `.project` file. The referred Java file is contained in a Git repository containing a couple of `.project` files. As you can see, the file format of those `.project` files did not change for almost two decades, e.g. https://github.com/eclipse/eclipse.platform.resources/commits/master/bundles/org.eclipse.core.resources/.project – howlger Apr 29 '21 at 23:36
  • Hi @howlger, Could you please give me the link where Eclipse documentation informs about .project sharing? – khadija zekraoui Apr 30 '21 at 07:24
  • @khadijazekraoui More than a decade ago this was already said for CVS, [for example here](https://wiki.eclipse.org/CVS_FAQ#What_is_the_.project_file.2C_and_should_I_release_it_to_CVS.3F). The file format didn't changed, even `` was kept although never used. The `.project` file is not related to Maven and Gradle. Maven, Gradle and .editorconfig files can have some overlap with the files in `.settings`, but cannot be derived from these files (think e.g. of save actions). – howlger Apr 30 '21 at 07:43
  • @howlger project file is for setting up the project structure, which is what maven and gradle are also used these days (among other things). So it is certainly related - if maven/gradle/similar configs would be missing, .project and other eclipse metadata would be more useful to store. – eis Apr 30 '21 at 08:03
  • @howlger "did not change for almost two decades" and "evolves as eclipse evolves" are not contradictory. Even if it does not change often, it does still change. – eis Apr 30 '21 at 08:04
  • @howlger in the CVS faq you link to it says .project should be stored since it contains "which projects it references and what type of project it is", among other things. That kind of information is certainly contained in maven/gradle/etc files nowadays. storing it in multiple locations is something one should avoid. – eis Apr 30 '21 at 08:06
  • @eis You said "evolves as eclipse evolves" and concluded that it must be version dependent. But the truth is that it was never changed, for the reason of not being version dependent. So, to the question _"Do .project file have any relation with the version of Eclipse?"_ the correct answer is "No, they have no relation" (all Eclipse versions understand the `.project` file created or maintained by any Eclipse version). You have misread the CVS FAQ. Please keep to the facts. If you think Eclipse projects, STS4, etc. do it wrong by having `pom.xml` and `.project` files, go and fill a bug report. – howlger Apr 30 '21 at 08:31
  • @howlger if you think I have stated something that is not a fact, you can always point that out. As you probably know, some versions of the .project file might be understood by some eclipse installations but not others. troubles like [these](https://stackoverflow.com/questions/7625537/missing-builderorg-maven-ide-eclipse-maven2builder) are not unheard of, when there are different versions of plugins and different eclipse versions. – eis Apr 30 '21 at 08:52
  • @eis No, you also [misread this (it's not about different versions)](https://stackoverflow.com/questions/7625537/missing-builderorg-maven-ide-eclipse-maven2builder). Every time I prove you wrong, you come up with something new. – howlger Apr 30 '21 at 09:57
  • @eis You claimed, _"evolves as eclipse evolves"_, but since it exists it has not been changed for backwards compatibility, even useless things were kept for that reason. If it evolved, which it doesn't, you could point to a change. It is impossible to refer to a non-existent change for me. Just look at the changes to the `.project` file closest to the wrong link you gave and ask yourself what problems there would have been not sharing the file (spoiler: some) and what problems there would have been using a much older version of Eclipse or different IDE/editor (spoiler: none). – howlger Apr 30 '21 at 10:45
  • @howlger in the example I gave there was configuration related to older version of plugin that worked in the older version of eclipse, but not anymore. in a newer version a change was required. -> the contents of .project file have changed -> it evolves as eclipse evolves. – eis Apr 30 '21 at 10:56
  • @eis In this case a plugin uses different IDs for its builder and a nature. This is a workaround because the `.project` does not evolve and does not contain version information. This is not ideal and very rare. However, it is still better than omitting the `.project` file, since otherwise Eclipse cannot tell you that some tooling support is missing. For example, if you have a project with an EMF model, Eclipse can detect by the `.project` file whether tooling support is missing and ask you to search for it in the Marketplace. Without the `.project` file, it would not work for unknown reasons. – howlger Apr 30 '21 at 11:37
  • Fun fact: [a year ago, the answer of an Eclipse committer has been deleted linking to the documentation that says](https://twitter.com/howlger/status/1255791801195167745): "[Make sure that the `.project` and `.classpath` files are under version control.](https://wiki.eclipse.org/FAQ_How_do_I_set_up_a_Java_project_to_share_in_a_repository%3F)" – howlger Apr 30 '21 at 13:02