How to force Maven to check the source end of a line?

I would like to end the end of the Unix line (\ n) in the Java sources of our projects for sequence reasons. Since many of us work under Windows, most IDEs are configured by default to use the Windows-style end of line (\ r \ n). We try to change these settings every time we set up a new workspace, but for some reason some files are executed when Windows shuts down.

Is there any Maven configuration or plugin that could help us embed the end of the line in Unix style, or at least warn us about files that are in Windows style?

Iโ€™m talking about PMD or Checkstyle, but it doesnโ€™t seem so easy. I also tested the Maven Enforcer Plugin, but I do not think it does this out of the box. I would have to create my own rule, but I would like to make sure that I do not reinvent the wheel :)

+4
source share
3 answers

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

You can use a regex for this (the end of the Windows line is \ r \ n, but you probably know this).

+5
source

We use the following Checkstyle configuration to force the end of 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> 
+3
source

I donโ€™t know how to check for a new line character, but I know how to fix it automatically (I believe this is even better.)

ANT has such a task, and maven can run ant tasks. Look here for details.

+2
source

All Articles