简体   繁体   中英

Maven Plugin to automatically generate setters/getters?

Is there a Maven Plugin that will automatically generate setters and getters with the corresponding JavaDocs?

I am aware that Eclipse/Netbeans will do this when you tell it to; however, it would be nice for the source to simply contain the skeleton and have Maven or another tool generate the repetitive stuff.

I would want to modify the source code so that a source jar can be compiled and used when debugging.

Thanks, Walter

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.

您可以尝试Modello ,它允许您指定一个模型,并通过modello-maven-plugin在构建过程中生成Java。

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM