[Maven is not so evil] Plexus-archives 2.3 is a life saver

written by MindTheGab on June 20, 2013 in agile and alfresco and alm and maven and opensource with 9 comments
Follow me!

MindTheGab

WW Manager, Expert Services at Alfresco Software
Grown in the flourishing Open Source Enterprise ecosystem of the last decade, bringing a wealth of expertise on ECM and Application Lifecycle Management, both in terms of Product and People leadership.

With a masters thesis on Business Process Re-engineering on a fully open source stack and 10 years in the tech business between Services, Sales and Engineering, he developed a full-spectrum technical and business expertise, in the context of large scale Enterprise Content Management projects for key government and Fortune 500 global customers.
Follow me!

Maven is very good with J2EE WARs. Resources, packaging, overlays.

I admit that if it wasn’t for the great features and clean development model imposed by the maven-war-plugin, I would not even probably looked at Maven in the first place when I developed the first version of the Maven Alfresco SDK.

Lately though, especially working with large WARs overlays like Alfresco (120MB) and Share (40MB), I have seen all my efforts for standardized development falling badly short on the rapid development side. Suddenly (on my Mac, or I assume on any Unix/Linux environment) my WAR overlays started to take minutes to complete, with a big so long to the quick dev-fix-test cycle. As a Java performance expert, I decided to debug it and understand where it was actually wasting time.

Turns out that for each and every unpacked resource from WAR overlays the Maven unarchiver would fork a chmod process, to modify some file permissions!!! (Windows users, you can stop reading here :)

Leaving out that I’m not sure of the original reason for this, I later found out (also thanks to Samuel, kudos!) that this was due to a misconfiguration of the plexus-archiver package, which instead of using native JVM chmod capabilities was forking the process. All details unfolded in a related maven-dependency-plugin issue, MDEP-368.

Basically turns out this properly fixed in plexus-archiver-2.3 (the Maven shared component used by plugins to manage ZIP & co. archives), where no process is forked and the overall WAR packaging / overlay time is reduced drastically. And now the fix, and later the wow effect (I hope) :)))

Luckily enough the fix is pretty simple and only requires to have your plugins (unless they do it already) depend explicitly on plexus-archiver version 2.3. In other words just add the following snippet (the example is for the maven-war-plugin, but you can use the trick for the maven-dependency-plugin and any other plugin you see poorly performing on resource unpacking) to your pom.xml:

 <plugin>
     <artifactId>maven-war-plugin</artifactId>
     <dependencies>
         <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-archiver</artifactId>
             <version>2.3</version>
         </dependency>
     </dependencies>
 </plugin>

EDIT: This is fixed in the maven-war-plugin version 2.4 (and you don’t need the explicit plexus-archiver dependency anymore), see related issue MWAR-280).

Just to give you an idea how the performance improvements with this little fix, I will use as an example the Maven Alfresco All-In-One Archetype, which allows to develop and run an Alfresco Repository, Share, Solr and an AMP in the same Maven multi-module project. The SDK currently does NOT use plexus-archiver 2.3 (there is an issue for it), so it’s extremely (and unnecessary) slow in the Alfresco and Share overlays.

After I created the project from the archetype as per docs, here’s the output of a simple

mindthemac:alfresco-parent mindthegab$ mvn clean install -DskipTests
...
[INFO] Reactor Summary:
[INFO]
[INFO] Quickstart of Alfresco and Share with DB and runner embedded  SUCCESS [0.978s]
[INFO] Alfresco AMP Module ............................... SUCCESS [11.271s]
[INFO] Alfresco Repository and Explorer Client ........... SUCCESS [4:10.599s]
[INFO] Alfresco Apache Solr customization ................ SUCCESS [6.504s]
[INFO] Alfresco Share Client ............................. SUCCESS [4:08.038s]
[INFO] Alfresco and Share Runner ......................... SUCCESS [0.045s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8:41.062s
[INFO] Finished at: Thu Jun 20 14:54:35 CEST 2013
[INFO] Final Memory: 38M/782M
[INFO] ------------------------------------------------------------------------

What? 8m41s total build time? 4 minutes for each WAR? On my very decent Mac 8GB RAM+SSD?

Such a slow cycle is just going to kill the Maven Alfresco Community, to be a little dramatic :)

And now, get ready for the wow…after applying the little plexus-archiver fix above (in the parent POM <plugins> or <pluginManagement> sections) this is the amazingly improved performance of the vary same build:

mindthemac:alfresco-parent mindthegab$ mvn clean install -DskipTests
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Quickstart of Alfresco and Share with DB and runner embedded  SUCCESS [0.848s]
[INFO] Alfresco AMP Module ............................... SUCCESS [5.630s]
[INFO] Alfresco Repository and Explorer Client ........... SUCCESS [35.372s]
[INFO] Alfresco Apache Solr customization ................ SUCCESS [5.054s]
[INFO] Alfresco Share Client ............................. SUCCESS [23.945s]
[INFO] Alfresco and Share Runner ......................... SUCCESS [0.019s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:13.143s
[INFO] Finished at: Thu Jun 20 15:56:43 CEST 2013
[INFO] Final Memory: 44M/496M
[INFO] ------------------------------------------------------------------------

WOW!!!  Only 1m13 total build time…a neat 85.96% build speed up :)

I think it’s really worth making sure this trick is known as it’s going to be a life saver to the Maven Alfresco SDK and I’m also using it to speed up our internal Alfresco Maven builds.

Hope you find this useful, to the next tip of this newly born Maven post series!

About Gabriele Columbro

Grown in the flourishing Open Source Enterprise ecosystem of the last decade, bringing a wealth of expertise on ECM and Application Lifecycle Management, both in terms of Product and People leadership. With a masters thesis on Business Process Re-engineering on a fully open source stack and 10 years in the tech business between Services, Sales and Engineering, he developed a full-spectrum technical and business expertise, in the context of large scale Enterprise Content Management projects for key government and Fortune 500 global customers.