6

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 ?

Alexandre Bourdin
  • 825
  • 1
  • 14
  • 30
  • If i correctly understand your first mojo compiles groovy scripts and produces some compiled classes (*.class files somewhere on the file system). These classes can be used to extract the SQL information from it and the third can load the scripts into the database. Binding the mojo's to the appropriate life cycle phase you have the way to transfer the information from one to an other mojo. Apart from that there are already existing plugins for compiling groovy code and loading sql scripts into database. Maybe this project is avaialable as Github project or something similar. – khmarbaise Jan 14 '14 at 14:21
  • You could write files to the ${project.build.directory}? Introduces some implicit coupling between the plugins, but if the input file names are configurable it should be fine. Then there is also [plugin context](http://maven.apache.org/ref/3.1.1/maven-plugin-api/apidocs/index.html), but that is most likely not appropriate for compiled files etc. . – Pyranja Jan 14 '14 at 14:24
  • I edited my question to add some details about what kind of data I want to transmit. It relies on our own compilation engine, so we don't want to use another plugin. The idea is to grab some information from compilation result (not from the compilation result file, but from some context information caught during compilation (errors, package path, etc). – Alexandre Bourdin Jan 14 '14 at 15:27

1 Answers1

6

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.

Alexandre Bourdin
  • 825
  • 1
  • 14
  • 30