为什么我的 Maven 插件没有获取父属性?
当我让一个插件扩展另一个插件时,它通常会继承父级的属性。 但有时它不起作用。 当插件加载时,父级的属性全部为 null
我可能做错了什么? 我将我的项目打包为 Maven 插件,并且构建正常。
When I make one plugin extend another it normally inherits the properties from the parent. Sometimes it doesn't work though.
When the plugin is loaded up, the properties from the parent are all null
What might I be doing wrong? I package my project as a maven-plugin and it builds ok.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己也见过这种情况,这让我抓狂,直到我调试了 Plexus 内部结构。 我猜当父级位于另一个插件中时,这些属性不会被继承?
如果是这种情况,下面的解释会有所帮助。 如果不是,则可能是 Javadoc 注释中的拼写错误。 Maven 将跳过任何它无法识别的标签而不发出警告。
如果不是这些,你能发布更多细节吗? 也许是 Mojo 失败的一个例子?
如果父级在另一个项目中,这就是您遇到问题的原因。
Maven 插件使用 Javadoc 注释来定义依赖项、目标声明和其他配置(Maven 2.1 引入了正确的 Java 注释,但几乎没有任何插件使用它们)。 安装/部署插件后,Javadoc 就会丢失,因此任何在另一个 jar 中扩展插件的插件都无法访问父级中 plexus 定义的属性。
不过有一个解决方法。 插件元数据输出到 META-INF/maven/plugin.xml。 有一个读取信息的第三方插件来自父 Mojo 的 plugin.xml 并将本地插件元数据与其合并。 然后您的插件应该可以正常工作。
I've seen this myself and it drove me mad until I debugged the Plexus internals. I'm guessing the properties are not inherited when the parent is in another plugin?
If that is the case, the explanation below will help. If it is not, it might be a typo in the Javadoc annotations. Maven will skip any tags it doesn't recognise without warning.
If it's neither of these, can you post a little more detail? perhaps an example of the failing Mojo?
If the parent is in another project, here's the reason why you're having problems.
Maven plugins use Javadoc annotations to define the dependencies, goal declarations, and other configurations (Maven 2.1 introduced proper Java annotations but hardly any plugins use them yet). Once the plugin has been installed/deployed the Javadoc is lost, so any plugin that extends a plugin in another jar won't have access to the plexus-defined properties in the parent.
There is a workaround though. The plugin metadata is output to META-INF/maven/plugin.xml. There is a third-party plugin that reads the information from the parent Mojo's plugin.xml and merges the local plugin metadata with it. Your plugin should then work as normal.