文件不以换行符结尾 [NewlineAtEndOfFile]

lob*_*lob 3 java eclipse newline file checkstyle

当尝试在我的项目上使用 mvn clean install 时,我收到这些错误:

[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.
Run Code Online (Sandbox Code Playgroud)

将段落或 \n 放在这些文件的末尾并不能解决此问题。在 Eclipse 下, Window >> Preferences >> Checkstyle >> Select the configuration file >>这些文件未列出。

使用:

  • Windows 10
  • 爪哇8
  • Eclipse Neon.1 (4.6.1)
  • Maven 3.0.4

Joe*_*ell 5

长话短说:

  1. 跑步git config core.autocrlf true
  2. 删除除以下之外的所有文件和文件夹.git
  3. 跑步git reset --hard HEAD

细节和根本原因:

  1. Git 行结束配置

    Windows 上的 Git 配置是此错误的根本原因。zanata-platform-platform它是用 Unix 风格的行结尾构建的。在 Windows 中,maven 会将 Unix 风格的行结尾误解LF为不正确的 Windows 行结尾CRLF

    第一步是重新配置 Windows 上安装的 git,以便在 git 生成文件时替换LFCRLF. 在 Windows 上,您可以使用以下命令编辑文件,CRLF但此配置告诉 git 在您提交或推送时进行CRLF转换LF

  2. 删除所有文件,同时保留.git包含历史记录的目录

  3. 让 git 新生成带有 Windows 风格行尾的文件。

  • 确实如此,但我认为这更有可能是 checkstyle 的 bug。我使用的所有 Windows 应用程序都知道 LF 结尾并正确处理它们,因此我将 autocrlf 切换为 false。现在 checkstyle 行为...顺便说一句,它可以使用 `NewlineAtEndOfFile` 模块属性进行配置:`<property name="lineSeparator" value="lf"/>`,但我更喜欢自动识别。 (3认同)