通过Maven插件执行在Mojo之间共享数据 [英] Share data between Mojo through Maven plugin execution

查看:104
本文介绍了通过Maven插件执行在Mojo之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Maven插件,该插件由3个继承了AbstractMojo的mojo组成.

长话短说,这3个Mojo习惯于:

  1. 编译一些时髦的脚本
  2. 使用从编译中提取的数据生成SQL脚本
  3. 将这些脚本加载到数据库

以前,我的第二个mojo继承了第一个,而第3个继承了第2个,他们都在execute()方法中调用了super.execute(),以便彼此可以级联.

我正在重写插件,以使其更加整洁和更好地设计,因此我删除了继承并希望依赖于Maven本机生命周期,将3个mojo绑定到compilepackagedeploy阶段. /p>

我面临的问题是我无法找出一种干净的方法将在第一行Mojo执行期间提取的数据传递给第二行Mojo(例如文件扩展名,是否正确编译了文件,打包路径等). ). Maven插件API中是否有任何可用的临时存储或缓存系统?

解决方案

由于没有直接的方法可以在Maven mojo之间共享数据,因此我选择将需要传递到CSV文件(XML, YAML或其他任何格式也可以完成这项工作.

与通过执行使用存储在内存中的某些缓存或上下文相比,优点是您可以执行一个目标,将其结果保存在文件系统中,然后在以后任何时候执行以下目标.

I am working on a Maven plugin, composed of 3 mojos inheriting AbstractMojo.

Long story short, these 3 mojos are used to :

  1. compile some groovy scripts
  2. generate SQL scripts with data extracted from compilation
  3. load these scripts to a database

Previously, my 2nd mojo inherited the 1st, and the 3rd inherited the 2nd, and they all called super.execute() in their execute() method, so that they could cascade from each other.

I am rewriting the plugin in order to make it cleaner and better designed, thus I removed inheritance and want to rely on Maven native lifecycle, binding the 3 mojos to compile, package and deploy phases.

The issue I am facing is that I can't figure out a clean way to pass to the 2nd mojo the data I extract during the 1st mojo's execution (like file extensions, if the file is correctly compiled, package path, etc). Is there any temporary storage or caching system available in the Maven plugin API ?

解决方案

As there is no straightforward way to share data between Maven mojos, I chose to write data I need to pass to the next Mojo in a CSV file (XML, YAML or any other format could have done the job as well).

The advantage over using some caching or context stored in memory through execution is that you can execute one goal, keep its result in filesystem, and then execute the following goals any time later.

这篇关于通过Maven插件执行在Mojo之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆