JEP 413, scheduled for Java 18, introduces a new @snippet tag for JavaDoc that allows embedding code examples from external source files rather than inline in comments. This solves long-standing problems: no more escaping special characters, proper editor support, and most importantly, snippets can be compiled and tested as part of the build so they never go stale. The post walks through configuring Maven's JavaDoc plugin with a snippet path pointing to src/test/java, shows how to define snippet regions, and demonstrates customization options like highlighting, linking class names, and replacing parts with placeholders. The Bean Validation API project is used as a practical example.
Sort: