Overview
When working with Liferay projects using Liferay IDE and Plugins SDK it becomes highly difficult to manage dependencies, as Liferay IDE or Plugins SDK by default uses Ant for building and deploying, though Liferay does support Maven based Plugins but as a seasoned Liferay Developer we will be inclined to use Ant preferred to Maven.
The problem rather I call it a difficulty arises when,
- The number of dependencies for our Portlet project increases and we need to maintain a version based configuration
- We need to use or integrate our Portlet application with an existing Maven based application from an Organizational build repository
In this article we will look at how we can use Maven dependency management in Plugins SDK by still using the default Ant based Liferay SDK build, you can use any of your existing Liferay Plugins SDK project which has external dependencies.
Technical Platform
I have tested this application on the following technical platform, this works irrespective of Operating System.
| Software | Version | Download Link |
|---|---|---|
| Liferay CE Portal Server (Tomcat) | 6.0.x | http://sourceforge.net/projects/lportal/files/Liferay%20Portal/6.0.6/liferay-portal-tomcat-6.0.6-20110225.zip/download |
| Liferay CE Plugins | SDK 6.0.x | http://sourceforge.net/projects/lportal/files/Liferay%20Portal/6.0.6/liferay-plugins-sdk-6.0.6-20110225.zip/download |
| Apache Ant | 1.7.x or above, preferred 1.8.x | http://ant.apache.org/bindownload.cgi |
| Apache Maven | 2.2.1 or above, preferred 3.0.3 | http://maven.apache.org/download.html |
| Apache Maven Ant Tasks | 2.2.1 or above | http://maven.apache.org/ant-tasks/download.html |
Setup and Installation
Assuming that you have downloaded and installed the above mentioned softwares, for the sake of convenience we will use the following variable names for respective installation DIR’s,
- $LIFERAY_HOME - the home directory where Liferay server is installed e.g. C:\lportal-6.0.6
- $LIFERAY_SDK_HOME - the home directory where Liferay server is installed e.g. C:\liferay-plugins-sdk-6.0.6
- $ANT_HOME - the home directory where ANT is installed e.g. C:\apache-ant-1.8.2
- $M3_HOME - the home directory where Maven 2.2.x is installed e.g. C:\apache-maven-3.03
Now copy the maven-ant-tasks-2.1.3.jar to $ANT_HOME/lib
Implementation
Let’s use the Liferay IDE to create a new Portlet plug-in look at Using Liferay Maven SDK or you can import the attached Liferay Google Maps demo project in to your workspace,
Open the build.xml of the project that has been created, by default the project build template looks like
Now to Mavenize the default ANT build.xml we do the following,
- Add the xmlns:artifact=” antlib:org.apache.maven.artifact.ant” to the element of the orginal build.xml
- Create a new ant target called “copy-dependencies”, this step is crucial, you can have any name for the target but then what the target does is important. This target will download (only time only) and copy the dependencies to docroot/WEB-INF/lib folder
- Add an ant call to “deploy” target within the “copy-dependencies”, this will enable the build.xml to follow the default Portlet application building and deploying post copying the dependencies
- Make the copy dependencies as the default target for the project
A example of build.xml with above configurations is available here
Observe the artifact:dependencies task portions those are important pieces of mavenizing our ant build. We add the dependencies to the project the same way we add them in Maven pom.xml with little bit of variation to the syntax.
After this once you execute the build in Portlets plug-in directory, it will first download the dependency jars if it does not exist in to the local Maven repository and they will added to the docroot/WEB-INF/lib directory when copy-dependencies target is called, which also includes call to the Liferay default deploy target
Voila! Now we are able to use the Maven dependency management with Liferay Plugins SDK default Ant build system. I hope this article has helped you, for further reading you can check the following links,

