Dive in Maven plugins for coffee addicts

Benoit Tellier
Jul 26, 2017 · 4 min read
A proof that even god needs coffee to be efficient at work in the morning!

It is well known that programmer is a device that turns coffee into code!

Thus, coffee supply is the determining factor of the entire software industry…

(In Hanoï situation recently got better: we gain unlimited free coffee supply at walking distance from our working room, greatly increasing our efficiency)

That being said, living in a capitalist world, and being cautious about the efficiency of the team I am in, I would like to enforce coffee drinking as a regular team practice. Let’s turn developers inefficient moments into drinking coffee moment, that would later on increase their productivity!

Thus the idea of serving coffee upon compilation had formed in my mind. Being a Java developer, being familiar with Maven, I decided to write a maven plugin for pouring coffee upon compilation.

Maven is a wonderful Java build tool. The Maven developers had the great idea to adopt a plugin architecture, that lets people write their own plugins. These plugins can be executed upon build. As you might imagine, Maven users have been committed to writing various really useful plugins:

  • XML defined websites. The kiss-cool effect: it executes for every Maven modules! Be prepared to use more than 8GB of RAM as the plugin is shipped with a memory leak. Also, I don’t know why, but I burned an SSD compiling a maven website for a 150+ maven module project…
  • The unmissable plugin that allows you to write markdown instead of XML for your website… May come with side effect, however…
  • Javadoc automatic generation. A bump of version of Java might turn benign warning like HTML formatting into kill the word error that makes your CI fail…
  • A plugin that checks every licence. I like failing builds because your test EML file does not contain the license text… The first thing you do: inactivate it.
  • And much more…

But there is much more around: some project I’m very familiar with go as far as to ship with 6+ execution related plugins (maven-war-plugin, exec-maven-plugin, javacc-maven-plugin, maven-jar-plugin, maven-source-plugin, etc…). Total count of plugins? 34 minimum, not counting the ones dirtily included in sub projects…

Of course, all of these plugins chose explicit names: animal-sniffer-maven-plugin, cobertura-maven-plugin, apache-rat-plugin, maven-pmd-plugin, maven-jxr-plugin, maven-doap-plugin, … I like the feeling of instantly knowing what a plugin does from its name, without searching for a minimal, laconic and partial documentation, not to mention endless StackOverflow threads of lost users.

Thus I felt naturally entitled to write a maven plugin to brew coffee during compilation.

I know, what a holly mission: bringing coffee to developpers!

So, tell me, how is this awesome, essential piece of technology works?

Well, it is based on the wildly adopted HTCPCP protocol! This protocol build by the IETF allows you to simply control any connected coffee pot on top of a well-described HTTP based protocol. It allows you to choose various coffee options, like spice to put in, alcohol to mix it with, topping or milk options.

Incomprehensibly, there was no HTCPCP library available in Java. (Understandable, Java ecosystem is well-known to find it hard to keep up with pre-1998 standards, just take a look at how hard it is to execute a plain SQL query, you will see). Thus, I had to come up with my own. The result is something that looks like this:

Wonderful, right?

The rest of the plugin code is wiring to control HTCPCPEngine from maven configuration.

In order to achieve this, one can very simply use the awesome maven-plugin-api along with the maven-plugin-annotations.

You have to write Mojo (whatever this means…) for the different actions you are willing to support, here starting and stopping the coffee machine. From there, the maven-plugin-plugin (original name, for sure!) will do the rest of the job and will provide you with a working plugin.

Here is a small overview of the plugin configuration for XML lovers:

I know, not boiler plate, not verbose and most of all intuitive! This is the magic of XML defined maven configuration.

I hope this short article would have convinced some heretics using JavaScript on a daily basis to drop the nvm/npm/gulp/bower/grunt craziness, and join the right side of the force with Maven! There’s nothing like the UNIX philosophy! Let’s build a tool that does everything, and anything, and let’s love it, let’s makes it even more floppy, even slower, even more counter intuitive!

Long live Java!

Long live maven!

Long live James!

Long live Linagora!

Linagora Engineering

We are Open Source Engineers, Hacking Awesome Stuff