Auto updating formatter in Eclipse

eclipse, eclipse-formatter, formatter

Solution

Introduction

Formatter, Code Templates, etc. can be stored as project specific settings in the folder `.settings/`. You don't necessarily need to re-import the Formatter in your workspace.

You can use project specific settings in combination with `svn:externals` to "inject" the formatter, code templates, etc. in your projects.

svn:externals:

Sometimes it is useful to construct a working copy that is made out of a number of different checkouts. For example, you may want different subdirectories to come from different locations in a repository, or perhaps from different repositories altogether.

Projects

- We have a java project named `com.xyz.codeconventions` where we added a project specific formatter and code templates. This project is under version control.

- For all the other projects we define a `svn:externals` property to "inject" the `.settings/` folder from the project `com.xyz.codeconventions` (This is the folder where the project specific data is stored)

- If you now want to change the formatter you can edit the project `com.xyz.codeconventions` and use `svn commit` to submit the changes. The team will have to `svn update` on all projects to get the latest version of the code formatter.

Configuration

For all projects which should use this formatter you have to define a svn:externals property.

Example for com.xyz.project1:

key                   value
----                  ------
svn:externals         http://path/to/com.xyz.codeconventions/.settings .settings

In Eclipse (in my case Subversive) you can add svn specific properties with `Team -> Set property...`.

Repository Layout

The repository structure in our case looks like this:

 <root>
   |
   +-- com.xyz.project1 # (svn:externals -> <root>/codeconventions/.settings .settings)
   |    |
   |    +-- src
   |    +-- <...> 
   +-- com.xyz.project2 # (svn:externals -> <root>/codeconventions/.settings .settings)
   |    |
   |    +-- src
   |    +-- <...> 
   +-- com.xyz.codeconventions
        |
        +-- .settings  # (this folder will get "injected" in project1 and project2)
             |
             +-- org.eclipse.jdt.core.prefs
             +-- org.eclipse.jdt.ui.prefs

Additional comments / Limitations

- This approach is for `svn` users only but if you use `git` there is something similar to svn:externals named Submodules.

- Make sure that in project1 and project2 are no `.settings/`-folder because with `svn:externals` it is not possible to overwrite existing files.

- If you have java projects which need completely different formatters or different files in the `.settings/` folder this approach is probably not what you are looking for. Our projects always have the same `.settings` files.

Sources

- SVN: Externals Definitions

- SVN: TortoiseSVN - External Items

- Git: Tools - Submodules

- Git: Working with subtree merge

- Eclipse Help: Code Formatter Preferences

- Eclipse Tip: Sharing Java project settings

Problem

We rely on Eclipse formatter in our project to enforce formatting conventions for us. It works great and we really like it. We keep the formatter file with our project in source control and ask everybody to import this formatter to Eclipse. The only serious problem is that whenever somebody modifies the formatter and commits the change, then every team member needs to manually "reimport" the formatter. And it's easy to forget about doing it, so we often end up with using different versions of formatter among the team. Is there any way to make Eclipse automatically use new version of formatter when the formatter file is updated? (I mean, could we just say to Eclipse "here's the path to formatter file, always use the current version of this file as a formatter"?) It would be great! Any ideas?

Original source

Related problems