File does not end with a newline [NewlineAtEndOfFile]
Solution 1
tl;dr:
- run
git config core.autocrlf true - remove all files and folders other than
.git - run
git reset --hard HEAD
detail and root cause:
-
Git line ending config
Git configuration on Windows is the root cause of this error.
zanata-platform-platformwhich is built with Unix style line ending. In windows, maven will misunderstands Unix style line endingLFas improper Windows line endingCRLF.First step is to re-configure git installed on Windows so that when git generate file replacing
LFtoCRLF. On Windows, you edit files withCRLFbut this config tells git to convertCRLFtoLFwhen you commit or push. Delete all files while keeping
.gitdirectory which contains historyLet git newly generate files with Windows style line ending.
Solution 2
The cause is a checkstyle rule called NewlineAtEndOfFile which prevents a successful build if any of the project's files does not have a new line at its end.
The rule says:
Rationale: Any source files and text files in general should end with a line separator to let other easily add new content at the end of file and "diff" command does not show previous lines as changed.
So what must be done, is simply to add a new line at the end of each of the files mentioned in the above logs:
. eclipse-code-formatter-js.xml
. eclipse-code-formatter.xml
. pom.xml
. README.txt
For more infos on this rule: checkstyle-NewlineAtEndOfFile-rule
lob
Updated on June 04, 2022Comments
-
lob 6 monthsWhen trying to use mvn clean install on my project I'm getting those errors:
[ERROR] C:\Users\lob\Downloads\zanata-platform-platform-4.0.0\zanata-platform-platform-4.0.0\parent\eclipse-code-formatter-js.xml:0: File does not end with a newline. [NewlineAtEndOfFile] [ERROR] C:\Users\lob\Downloads\zanata-platform-platform-4.0.0\zanata-platform-platform-4.0.0\parent\eclipse-code-formatter.xml:0: File does not end with a newline. [NewlineAtEndOfFile] [ERROR] C:\Users\lob\Downloads\zanata-platform-platform-4.0.0\zanata-platform-platform-4.0.0\parent\pom.xml:0: File does not end with a newline. [NewlineAtEndOfFile] [ERROR] C:\Users\lob\Downloads\zanata-platform-platform-4.0.0\zanata-platform-platform-4.0.0\parent\README.txt:0: File does not end with a newline. [NewlineAtEndOfFile] Audit done. [INFO] There are 4 errors reported by Checkstyle 7.2 with zanata-build-tools/checkstyle.xml ruleset. [ERROR] eclipse-code-formatter-js.xml:[0] (misc) NewlineAtEndOfFile: File does not end with a newline. [ERROR] eclipse-code-formatter.xml:[0] (misc) NewlineAtEndOfFile: File does not end with a newline. [ERROR] pom.xml:[0] (misc) NewlineAtEndOfFile: File does not end with a newline. [ERROR] README.txt:[0] (misc) NewlineAtEndOfFile: File does not end with a newline.Putting paragraphs or \n at the end of those files does not solve this issue. In Eclipse under
Window >> Preferences >> Checkstyle >> Select the configuration file >>those files aren't listed.Using:
- Windows 10
- Java 8
- Eclipse Neon.1 (4.6.1)
- Maven 3.0.4
-
Alexander Radchenko over 2 yearsThats the case, but I think it's more likely to be the checkstyle bug. All Windows applications I use know about LF endings and treat them correctly, so I switched autocrlf to false. Now that checkstyle behavior... BTW it is configurable withNewlineAtEndOfFilemodule property:<property name="lineSeparator" value="lf"/>, but I would prefer automatic recognition.