Monday, November 17, 2014

Do you really want to speed up your Maven compile/packaging? Then takari lifecycle plugin is the answer. #maven #mvn #takari

Like many of you out there, I am working with a multi module Maven project. It is not a huge one comparing to many systems out there, it has 15 modules, with 3 different ear deployments, lots of parametrization with property files and around 100K lines of Java code. During peak development times, the code is heavily refactored, due it's legacy origins and so the need for continuous compiling/packaging and deployment, for every developer. 

Despite the steep learning curve all these years I have embraced Maven and it's philosophy. I am not saying that is perfect, but I truly believe that is a good tool, still relevant, especially while your project and team grows as you grow your project. (This post is not about Maven evangelism though). 

So, one of the problems we had on our team is that, despite switching the right flags, breaking and packaging our code into modules, using profiles and all the 'tools' maven provides, our build and packaging time was  slowly starting to increase, hitting the 1 minute threshold after a complete clean. Our main compiler was Sun/Oracle Javac and the time was monitored through packaging from the command line and not  through the IDE, where you can see different times depending on the 'Maven Integration' and internal compiler invoked by each tool. [My reference machine is my good old MacBookPro 2009, Core 2 Duo 2.5, with an Vertex 3 SSD (trim enabled)]

Recently while I was browsing Jason Van Zyl's (the father of Maven)  twitter account I discovered  the takari lifecycle plugin. Jason and his team are creating tools and plugins for the Maven ecosystem, that I hope to  bring  the much anticipated evolution  on the Maven ecosystem that the community of Maven seeks for a many years now. 

To cut a long story short, the takari lifecycle plugin, is an alternative Maven lifecycle implementation, that covers 5 different plugins into one. Once you activate it, it will take over, and invoke it's own implementation of the following 5  
  • resources plugin
  • compiler plugin
  • jar plugin
  • install plugin
  • deploy plugin
You can read about it here. The great thing at least in my case was the compiler plugin, that internally implements a incremental compilation strategy based on a mechanism that can detect changes on source files and resources!!

In order to understand the difference, when using the takari compiler plugin on your maven build compared with the classic compiler plugin and javac (which most probably many of you use), I am going to share a table from this blog post (explaining incremental compilation).

It is far more obvious that if you choose to invoke JDT instead of Javac, the results are going to be even better. Currently we stick with Javac, but the above diagram made me change the default compiler on my IntelliJ IDE, especially when I do refactoring and changes all around, JDT was anyway far better on incremental compilation comparing to Javac.

How to add takari to my build? Is it safe

Well in my case (and I guess for many of you out there), I just followed the proposed way here. I activated the plugin in my parent pom and then changed the packaging type for all my jar modules, into 'takari-jar'. 

  takari-jar

This is not, eventually the change is so easy that you can revert it back.

 The day that I pushed the takari lifecycle change on our git repo, after half an hour I started hearing 'wowss' and 'yeees' from my team members. Repated packaging on changes is very very cheap, changes on resources files and properties ensure that we will get a fresh package when needed. Our repacking times dropped to more than 50%-60%.

If you happen to have the same issues with your Maven build, I trully encourage you to try takari for a day - it will same you and your team some serious time.

I also want to note, that takari is free and despite the fact that is evolved and updated by the takari team for an unnamed 'big' client, the team is free to give it away for free and share it with the community. So thank you very much for this!!!The plugin is can be found on maven central.

The takari team is doing a weekly google hangout, information can be found here, I want to apologize that I have not managed yet to attend one, maybe soon enough.

So go Maven! go Takari!

2 comments:

  1. Replies
    1. There is no support, but on the other hand, it is not needed, it just a different name, when it comes to xml config syntax. When it comes to the actual engine itself, it can be invoked as usual from the IDE. Meaning, IntelliJ will keep using your Maven setup to do what can do with it.

      Delete