Making Alfresco Maven Friendly

Since Alfresco source code is not managed by maven, implementing Alfresco extensions (AMP extensions) even simple JAR extensions with maven is very painful.

Actually maven aside, Alfresco’s extension mechanism is itself very basic or rather primitive and based on MMT (Module Management Tool). MMT is a executable jar file for overlaying AMP’s (Alfresco Module Plugin) into Alfresco war file. The simple steps are;

  • Extracting Alfresco war file
  • Extracting AMP
  • Copying everything inside the AMP into extracted war file
  • Re-packaging everything as war file

It is just the automatized way of patching a war file. I am sure every developer did the same in order to patch a production web application instead of creating a new release and opening a ticket for deployment 🙂 It is the dirty way of doing things.

Luckily there is a maven plugin (maven-amp-plugin) that makes developing AMP’s using Maven. Thanks to sourcesense (they are the Alfresco partner behind the plugin), ironically they just like their motto, they made opensource make sense 🙂

What I don’t get is why these kind of helpers are not provided by Alfresco. I am not saying that just to support Maven you have to use Maven. You can still continue to use Ant or you can even use your own scripts to manage your build process but if you are developing an enterprise application you have to support all the major build environment. BTW the majority of the world is using Maven.

Anyway even maven-amp-plugin makes everything much easier, it is not also perfect. What the plugin is the same steps listed above within Maven build lifecycle and some more conventions to manage configurations, etc.

I am saying that it is not perfect because there are some certain things it cannot do, like, managing the dependencies. Because it is using MMT behind, there is no way to manage the dependencies. Let’s say you have an AMP and you have a dependency to commons-lang-2.5 and Alfresco already has commons-lang-2.4, in this case you will end up with a war file that contains both the commons-lang-2.5 and commons-lang-2.4.

Or let’s say you are trying to write a simple unit test for a class that touches some Alfresco services, etc. In this case you have add all the dependencies that is being used by Alfresco as a test dependency to make your test work. However there is no way to do use the correct versions because the dependencies inside Alfresco war file is not managed by Maven.

READ  Decorating Django views that require Google Authorization with python decorators

I tried to manage the modules we are developing using maven-amp-plugin but managing dependencies became very painful. So I finally decided to build a pom to include all the dependencies those exist in Alfresco war file and include it as a dependency from alfresco module project instead of declaring all the dependencies one by one. As soon as I am finished, I will attach the pom to this post.

As promised, I created a pom file and listed all the dependencies inside Alfresco war file in this pom file. Since it was not possible to find all the dependencies inside the war file in 3rd party public maven repositories, I launched an Amazon EC2 Micro instance, installed Sonatype Nexus and deployed custom dependencies with groupId org.alfresco.sdk.

I also created an Alfresco war file with an empty WEB-INF\lib folder, why? Because it is the idea; we will manage all the dependencies using maven and overlay the amp modules into this war file. All you have to do is to use this war file with your amp module and also add a dependency to alfresco-dep artifact as follows.

READ  How to add alias commands in Ubuntu

If you have any questions, just make a comment, I will try to answer ASAP.

P.S. If you want to do the same thing for another Alfresco version, feel free, that is why we use Github. I can also create a user so that you can also upload custom artifacts to maven repository. Just let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *