Maven Plugin to automatically generate setters/getters?

偶尔善良 提交于 2019-12-05 23:29:38
Dominic Mitchell

This isn't necessarily something that you want maven to do for you. It will make working with the code in the IDE harder, as the IDE won't necessarily know about the generated code unless it has a plugin that understands Lombok's notation. IntelliJ has such a plugin available.

That said, project lombok aims to do this properly through the use of an @Data annotation. It looks like it works well, but I haven't tried it. It supports a number of environments and IDEs through plugins, including Maven, Eclipse, IntelliJ and Netbeans. There are a few caveats with Netbeans currently, see the project documentation.

You could try Modello, it allows you to specify a model and let the java be generated during the build by the modello-maven-plugin.

I know you asked for a Maven plugin but there is annotation based project that takes care of many boilerplate code issues in Java:

http://projectlombok.org

There is a use case that doesn't work with Eclipse and the mouse. Sometimes you need accessors in generated Java files, say, from an IDL specification. One example would be if the classes are further processed by an ORM framework.

Now, how can this easily be done with Maven? Of course, it's possible to script it or use the replacer plugin; but is there any off-the-shelf solution?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!