Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of Checkstyle message 'File does not end with a newline.'

I'm working with a Maven (jar) Project in Netbeans (Windows), which creates Checkstyle reports with the Maven Checkstyle plugin.

No matter what I do, I always get the message: File does not end with a newline for Java class files.

What can I do/configure in either Netbeans or Checkstyle to get rid of the message ?

Versions of used software:

  • WinXP SP3
  • Netbeans 6.7 RC1 (happens with 6.5 too)
  • Maven 2.0.9
  • Maven Checkstyle Plugin 2.2
  • Java 1.6 (Update 14)
like image 940
Michael Pralow Avatar asked Jun 15 '09 16:06

Michael Pralow


People also ask

How do you get a checkstyle violation?

To view to violation report, go to Window -> Show View -> Other, and search for Checkstyle. Options for Violations and Violations Chart should be displayed.

What is Maven checkstyle plugin?

The Checkstyle Plugin generates a report regarding the code style used by the developers. For more information about Checkstyle, see https://checkstyle.org/. This version of the plugin uses Checkstyle 9.3 by default and requires Java 8. But you can upgrade the version used at runtime.


2 Answers

In my case that was a problem with improper configuration of that checker. By default it uses system default convention of line endings. I was working on windows and the project was using unix-style line endings. I don't think ignoring the warning is the best strategy, so what I've done is:

<module name="Checker">     <module name="NewlineAtEndOfFile">         <property name="lineSeparator" value="lf" />     </module> </module> 
like image 115
Alexey Voinov Avatar answered Sep 25 '22 05:09

Alexey Voinov


Put a newline at the end of the file
or
configure CheckStyle not to care.

<module name="Checker">     <!-- stuff deleted -->     <module name="NewlineAtEndOfFile">         <property name="severity" value="ignore" />     </module> 

You also have to tell the Maven Checkstyle plugin to use your checkstyle config file.

<plugin>     <artifactId>maven-checkstyle-plugin</artifactId>     <configuration>         <configLocation>${basedir}/yourCheckstyle.xml</configLocation>     </configuration> </plugin> 
like image 20
Jon Strayer Avatar answered Sep 23 '22 05:09

Jon Strayer