Since Checkstyle 5.0
For Java SE8 and above, placement of package annotations in the package-info.java file is enforced by the compiler and this check is not necessary.
For Java SE7 and below, the Java Language Specification highly recommends but doesn't require that annotations are placed in the package-info.java file, and this check can help to enforce that placement.
See Java Language Specification, §7.4.1 for more info.
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="PackageAnnotation"/> </module> </module>
Example of class with violation:
@Deprecated package com.puppycrawl.tools.checkstyle.checks.annotation.packageannotation; // violation above, 'Package annotations must be in the package-info.java info.' class Example1 {}
Example of class without violation:
package com.puppycrawl.tools.checkstyle.checks.annotation.packageannotation; class Example2 {}
Example of validating package-info.java:
@Deprecated package com.puppycrawl.tools.checkstyle.checks.annotation.packageannotation.example3;
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.annotation