Question

I would like to enforce Unix style end-of-line (\n) in Java sources of our projects for consistency reasons. As many of us work under Windows, most IDEs are configured by default to use Windows style end-of-line (\r\n). We try to change that settings each time we configure a new workspace but for some reasons, some files are commited with Windows end-of-line.

Is there any Maven configuration or plugin which could help us enforcing the Unix style end-of-line or, at least, warning us of the files that are in Windows style?

I though about PMD or Checkstyle first but it doesn't appear to be that simple. I've also checked Maven Enforcer Plugin but I don't think it do that out-of-the box. I should be able to create my own rule but I'd like to make sure I don't reinvent the wheel :)

Was it helpful?

Solution

Use Checkstyle, we used it successfully in our project to enforce Unix line endings.

You can use a regular expression to do this ( a windows line ending is \r\n, but you probably know that).

OTHER TIPS

We use the following Checkstyle config to enforce UNIX line endings:

<module name="RegexpMultiline">
    <property name="format" value="\r\n"/>
    <property name="maximum" value="0"/>
    <property name="message" value="Do not use Windows line endings"/>
</module>

I do not know how to check the new line character but I know how to fix it automatically (I believe this is even better.)

ANT has such task and maven can run ant tasks. Take a look here for details

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top