简体   繁体   English

Maven插件可以自动生成设置器/获取器?

[英]Maven Plugin to automatically generate setters/getters?

Is there a Maven Plugin that will automatically generate setters and getters with the corresponding JavaDocs? 是否有一个Maven插件会自动使用相应的JavaDocs生成设置器和获取器?

I am aware that Eclipse/Netbeans will do this when you tell it to; 我知道,当您告诉Eclipse / Netbeans时,它将这样做。 however, it would be nice for the source to simply contain the skeleton and have Maven or another tool generate the repetitive stuff. 但是,对于源来说,仅包含骨骼并让Maven或其他工具生成重复的内容将是很好的。

I would want to modify the source code so that a source jar can be compiled and used when debugging. 我想修改源代码,以便在调试时可以编译和使用源jar。

Thanks, Walter 谢谢,沃尔特

This isn't necessarily something that you want maven to do for you. 这不一定是您希望Maven为您做的事情。 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. 由于IDE不一定知道所生成的代码,除非它具有能够理解Lombok表示法的插件,否则它将使在IDE中的代码处理变得更加困难。 IntelliJ has such a plugin available. IntelliJ有这样的插件可用。

That said, project lombok aims to do this properly through the use of an @Data annotation. 也就是说, lombok项目旨在通过使用@Data批注正确地做到这一点。 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. 它通过插件支持许多环境和IDE,包括Maven,Eclipse,IntelliJ和Netbeans。 There are a few caveats with Netbeans currently, see the project documentation. 当前有关于Netbeans的一些警告,请参阅项目文档。

您可以尝试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: 我知道您要求一个Maven插件,但是有一个基于注释的项目,可以解决Java中的许多样板代码问题:

http://projectlombok.org http://projectlombok.org

There is a use case that doesn't work with Eclipse and the mouse. 有一个用例不适用于Eclipse和鼠标。 Sometimes you need accessors in generated Java files, say, from an IDL specification. 有时,例如,根据IDL规范,您需要在生成的Java文件中使用访问器。 One example would be if the classes are further processed by an ORM framework. 一个示例是类是否由ORM框架进一步处理。

Now, how can this easily be done with Maven? 现在,如何使用Maven轻松地做到这一点? Of course, it's possible to script it or use the replacer plugin; 当然,可以编写脚本或使用替换插件。 but is there any off-the-shelf solution? 但是有没有现成的解决方案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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