I want to apply an annotation on all of my classes and I am trying the best way to do so.
So far I am stuck with the package-info.java file that can annotate a whole package, but not the class files contained in the sub-packages. Is there a more efficient way other than adding 100 identical package-info.java files in my project that only contain a single annotation?
thanks
解决方案
It looks like there is no way to do this.
I have added a static analysis checkstyle check for those package-info.java to make sure they are always there.
See: http://checkstyle.sourceforge.net/config_javadoc.html for more details.
Then if you run checkstyle static analysis on the project, it will complain for any missing package-info.java file.
Finally, to suppress the checkstyle rule on the tests, and on the package where the package annotation definition exists use this suppression rule:
博主探讨了如何避免为项目中的每个子包手动创建并维护众多重复的package-info.java文件,以应用单一注解。通过Checkstyle实现静态分析检查,并使用suppression规则处理测试和已注解包的情况。
389

被折叠的 条评论
为什么被折叠?



