Maven code formatting plugin for ImageJ / SciJava / Imglib2 git projects

I would suggest to have a git hook, that automatically format the code before a commit is made.
This git hook code be installed into the ImageJ / SciJava / Imglib2 git projects:

There’s a maven plugin for code formatting, that uses exclipse code style settings. I use is in

It only needs to by configured in the pom.xml:

It refers to the eclipse style settings stored in the same project:

When this is configured correctly, the simple command: mvn formatter:format will format the project correctly. Nothing else need’s to be installed. There is also a second maven plugin for organizing the imports.

I would suggest that we add to the ImageJ / SciJava / Imglib2 git repositorys. Together with a (optional) git hook. Something similar to the “travisify” script to install this would be nice.

@ctrueden @tpietzsch What do you think?

I think @turekg could be the one to make this happen. And it would solve all our code formatting problems. :heart:


Love the idea!

Here is a plugin we use for automatically organizing the Java imports in the CSBDeep project pom.xml:

							<goal>sort</goal><!-- runs at process-sources phase by default -->

@maarzt @turekg Do you have time to thoroughly develop, test and maintain rules that work really well in 99.9% of cases? And write & maintain the documentation for how to set them up on the ImageJ wiki? If so, then I am :+1: :+1: in favor.

Some challenges are:

  • The current ImageJ rules format certain code structures badly. Ideally, another pass should be done tuning the rules to produce a pleasing result in more cases.
  • ImageJ+SciJava, ImgLib2 and SciView all have different formatting rules, The rules are per organization. I would hate to have to commit the rules to every single repository—better would be for each org to have a single code-style repository or some such, and for the pom-scijava-base parent to somehow intelligently pull the right rules for each project.

What I want to avoid is a bunch of this stuff getting committed to many repositories, and then not properly maintained, so it becomes a bit rotting aspect of the build system over time. Or rules committed haphazardly across dozens of repositories, and then slowly diverging over months and years, with the rules missing by default from newly created repositories.


@ctrueden I think the rules should be the same across all projects. The point of automatic formatting is to present readable code to new contributors wanting to contribute and also to make code readable when updating. So it does not have to be perfect (at least not in the beginning), but for the sake of upkeep simplicity it should be the same everywhere. Given that we can’t control what people do during actual development (you can only do that successfully when everyone is in the same room or at least the group is small) this is a good solution. Of course people will be welcome to use the templates as well, but in my experience if this is adopted for just half the people it’s amazing.

@turekg Please feel free to lay out a concrete plan that addresses my points above!

1 Like

No I don’t want to write new code formatting rules. But we have existing ones and we could use just them:

I totally agree, committing the code formatting rules to every project is a bad idea. Having one maven artifact that contains the code formatting rules is much better. Let’s do it like this. pom-scijava should refer to that maven artifact and configure the maven formatter plugin accordingly. Projects like imglib2, scenery would than only need to set one property in the pom.xml to select the correct formatting.

1 Like

I set up a maven project that contains code formatting rules for imagej, imglib2 and scifio:

And made a PR to configure maven code formatter in pom-scijava:


Thanks @maarzt. If I don’t get to it before my post-Learnathon CSBD visit, let’s get it sorted then. And the plot service, too! >_<