Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why
(Redirected from Liferay Maven SDK)

Introduction#

Latest efforts relating Maven and Liferay have been focused in providing official maven artifacts for Liferay as well as porting our plugins sdk to Maven.

Our goal is to provide our CE releases through our own public repository as well as provide means for our EE customers to install the EE versions artifacts to their local maven repository.

If you have ever worked with enterprise projects using maven you already know how important a local maven repository and proxy is. For those not so familiar with Maven a proxy is a server that proxies your requests to public Maven repositories and caches the artifacts locally for faster and more reliable access. Most maven proxies can also host private repositories used for hosting your company's private artifacts. Having a local proxy / repository makes your maven builds much faster and more reliable than accessing remote repositories that might even sometimes be unavailable.

Installing a maven proxy / repository#

First step is to install and setup Nexus. Nexus is a open source maven repository manager that can proxy to other repositories as well as host repositories. If you just want to try things locally you can skip this step.

  1. Download latest Nexus such as nexus-webapp-1.4.0-bundle.zip
  2. Follow the installation directions of the Nexus book http://nexus.sonatype.org/documentation.html
  3. Startup nexus
  4. Open your browser to your newly created nexus (if you installed it locally it could be accessed by opening http://localhost:8080/nexus)
  5. Login as administrator (default login is admin / admin123)
  6. Go to Repositories and click Add -> Hosted Repository
  7. Give the repository following information and click save
Repository ID: liferay-ce-releases
Repostory Name: Liferay CE Release Repository
Provider: Maven2 Repository
Repository Policy: Release
  1. Create another hosted repository with following information
Repository ID: liferay-ce-snapshots
Repository Name: Liferay CE Snapshot Repository
Provider: Maven2 Repository
Repository Policy: Snapshot

Now you have a repository ready for Liferay's Maven artifacts. Next step is to configure your maven to be able to upload artifacts to that repository.

Configuring Maven Settings#

Open your $HOME/.m2/settings.xml (if the file does not exist create it). Add the servers segment to your settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings>
     <servers>
          <server>
               <id>liferay</id>
               <username>admin</username>
               <password>admin123</password>
          </server>
     </servers>
</settings>

You might also want to make your Nexus as your maven proxy. To do that just add following xml segment to your settings.xml right before servers element.

<mirrors>
     <mirror>
          <id>local</id>
          <name>Local mirror repository</name>
          <url>http://localhost:8080/nexus/content/groups/public</url>
          <mirrorOf>*</mirrorOf>
     </mirror>
</mirrors>

Installing Liferay Artifacts to Repository#

Next we will install the Liferay Maven artifacts to your repository. First you need to checkout Liferay code from the SVN.

svn --username guest co svn://svn.liferay.com/repos/public/portal/trunk portal-trunk

Guest user does not require password.

Then create a release.${username}.properties file and add

maven.url=http://localhost:8080/nexus/content/repositories/liferay-ce-snapshots

Build Liferay artifacts by running

ant clean start jar

Now you can deploy the Liferay artifacts to your maven repository by running

ant -f build-maven.xml deploy-artifacts

If you only want to have them locally without a maven repository you can run the install task instead of deploy

ant -f build-maven.xml install-artifacts

Now you can add Liferay dependencies to your maven project. Following artifacts are available:

<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>portal-client</artifactId>
	<version>6.0-SNAPSHOT</version>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>portal-impl</artifactId>
	<version>6.0-SNAPSHOT</version>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>portal-kernel</artifactId>
	<version>6.0-SNAPSHOT</version>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>portal-service</artifactId>
	<version>6.0-SNAPSHOT</version>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>portal-web</artifactId>
	<version>6.0-SNAPSHOT</version>
	<scope>provided</scope>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>util-bridges</artifactId>
	<version>6.0-SNAPSHOT</version>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>util-java</artifactId>
	<version>6.0-SNAPSHOT</version>
</dependency>
<dependency>
	<groupId>com.liferay.portal</groupId>
	<artifactId>util-taglib</artifactId>
	<version>6.0-SNAPSHOT</version>
</dependency>

NOTE portal-impl and portal-web are provided for maven plugins and should never be added as dependency to your Liferay plugins.

Installing the Liferay Maven SDK#

To take full advantage of Maven we are porting the functionality of out ant based Plugins SDK to Maven. To use it you need to install it locally. To install the Liferay maven plugins and archetypes go into support-maven folder and run

mvn install

Now the Liferay Maven SDK is installed and ready to use. We've implemented a portlet archetype and deployer plugin.

Creating a Portlet Plugin#

Move to the folder where you want to create your portlet and run

mvn archetype:generate

From the list select liferay-portlet-archetype and provide your project groupId, artifactId and version for the portlet project.

You're portlet project's pom.xml has two properties liferay.auto.deploy.dir and liferay.version. These properties are usually moved to your parent pom.xml or settings.xml so that you don't have to adjust them for every single plugin you create. Set the liferay.auto.deploy.dir to point to the Liferay autodeploy directory of your Liferay bundle. This is where the deploy plugin will copy your portlet. Now you are ready deploy your newly created portlet. You can deploy it by running

mvn liferay:deploy

Future Plans#

We are also in the process of adding archetypes for themes, hooks and layouts as well as providing portlet archetypes for different types of portlets like JSP, Spring MVC, JSF etc.

If you are using 5.2.3 CE and want to take advantage of Maven for building Liferay portlets Milen Dyankov a Liferay community member has done also great work on a Maven SDK for 5.2.3 CE. You can find more about it from GitHub

(Extracted from Mika Koivisto's blog)

0 Attachments
99788 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Service builder doesn't work in the latest... jonathan doklovic June 17, 2010 1:22 PM
Hey Jonathan, have you figured out why it... Jakub Liska October 20, 2010 4:08 PM
the maven-archetype doesn't create WEB-INF/sql... Jakub Liska October 20, 2010 4:52 PM
That's not what I wanted to say :-) the... Jakub Liska October 20, 2010 4:59 PM
Jakub, Were you able to run the service... Brian Ko November 3, 2010 8:16 AM
I was not able to use this notes with liferay... Baptiste Grenier June 23, 2010 4:10 AM
Maven archetype for themes I use maven to build... Sverker Abrahamsson August 6, 2010 7:11 AM
Any update on the Spring/JSF archetypes? Peter Mesotten October 8, 2010 12:26 AM
Hi there, It works great. It created a basic... Brian Ko November 1, 2010 6:14 PM
Please ignore my previous email. I did not see... Brian Ko November 1, 2010 6:21 PM
With Liferay CE 6.0.5, Maven service builder... Shinobi vn January 13, 2011 11:36 PM
Since instructions on this page are not... Petr Vlček March 25, 2011 2:21 AM
Thank you Petr. Exactly what i was looking for.... Tom Mahy June 2, 2011 1:40 AM
Hey all, Hours of Googling on this has not... Lorin Sutton June 2, 2011 12:42 PM
Lorin, did you try...? mvn liferay:build-service Jerry Thome July 6, 2011 12:00 PM
I followed the instructions Petr Vlček added,... Rollin Crittendon December 2, 2011 6:51 AM
I was also wondering for gpg keys do we use... Rollin Crittendon December 2, 2011 7:20 AM
I found my maven settings file had a format... Rollin Crittendon December 2, 2011 8:11 AM
Hello Everyone I'm testing for the first time... Gerald Perellano December 12, 2011 5:42 AM
Hi everybody. Is there any documentation about... David García González March 19, 2012 3:07 AM
It looks like the Maven artifacts have been... Sean Champ June 30, 2012 7:48 AM
Hi, I created a maven-liferay-theme project... Tirthankar Bhadra August 17, 2012 3:56 AM
Hi, I need to use Service Builder but with... Rahul Saraswat January 10, 2013 6:09 AM
Hi Everyone, I need to use Service Builder but... Rahul Saraswat January 10, 2013 6:10 AM
Hi, If I create maven project using liferay... Joga Krish April 5, 2013 4:36 AM

Service builder doesn't work in the latest maven sdk.
It generates code fine, but it does not create the -services.jar or any of the sql scripts that should be packaged with the war.
Posted on 6/17/10 1:22 PM.
I was not able to use this notes with liferay portal 6.0.2 branche, more details in this forum thread: http://www.liferay.com/community/forums/-/message_boards/message/5147190
Posted on 6/23/10 4:10 AM.
Maven archetype for themes
I use maven to build themes, first I have a maven project which creates the base artifacts for _styled, _unstyled and classic themes. Then I create my theme project from an archetype which extend the desired theme.

Under \src\main\webapp\ in my project is the same as _diff in the traditional structure, I find this much easier to work with.

The files can be downloaded from here:
http://www.abrahamsson.com/theme-base.zip
http://www.abrahamsson.com/theme-a­rchetype-1.0.jar

Run first maven in the base project, adjust the path to liferay installation. Then generate the new theme project with the following command line:

mvn archetype:generate -DarchetypeGroupId=com.liferay -DarchetypeArtifactId=theme-archetype -DarchetypeVersion=1.0
Posted on 8/6/10 7:11 AM.
Any update on the Spring/JSF archetypes?
Posted on 10/8/10 12:26 AM.
Hey Jonathan,

have you figured out why it wasn't generating the jar and sql scripts ? Cause I'm using current trunk now, and it still doesn't generate them.
Posted on 10/20/10 4:08 PM in reply to jonathan doklovic.
the maven-archetype doesn't create WEB-INF/sql directory and without it servicebuidler.java doesn't create them....

as to the libraries, in pom definition, portlet-service.jar is marked as provided and util-*.jar are not...in fact it should be the other way around, because during deployment util-*.jars are copied over, but portlet-service.jar should be shipped with portlet...
Posted on 10/20/10 4:52 PM in reply to Jakub Liska.
That's not what I wanted to say :-) the "provided" thing, the problem is that the libraries are created with version stamp, and when they are deployed, hot deployer doesn't see them and copy over new util-*.jars to the portlet lib directory and they are doubled there
Posted on 10/20/10 4:59 PM in reply to Jakub Liska.
Hi there,
It works great. It created a basic structure for the liferay portlet projects. Now the issue is how we can use the service builder to create the java code which conforms to the maven folder structure so that we can build the war file from maven. Do you have a plan to provide the service builder for maven? Thank you.
Brian
Posted on 11/1/10 6:14 PM.
Please ignore my previous email. I did not see the liferay-maven-plugin in pom.xml.
Posted on 11/1/10 6:21 PM in reply to Brian Ko.
Jakub,

Were you able to run the service builder (mvn -P build-service install) on the project you created? I got build error as it cannot locate the liferay-lib-5.2.3-r2.pom.

Brian
Posted on 11/3/10 8:16 AM in reply to Jakub Liska.
With Liferay CE 6.0.5, Maven service builder doesn't create the folder WEB-INF/sql, so you may have issue when deploying the portlet. Create the folder manually and call service builder again (mvn liferay:build-service) will fix this problem.
Posted on 1/13/11 11:36 PM.
Since instructions on this page are not complete (at least for version 6.0.6), I would like to summarize missing points found in related forum posts that helped me to get it working:

1. Install Maven, Ant and Nexus following instructions on this page.
2. Install GPG (http://www.gnupg.org)
3. Generate GPG key with gpg --gen-key
4. Create your release.username.properties with following contents:

lf.version=6.0.6
maven.url=http://path_to_your_repository
maven.repositor­y.id=liferay # as in settings.xml
maven.version=${lf.version}
gpg.keymame=XXXXX # to get keyname run command gpg --list-keys
gpg.passphrase=XXXXX

5. Build Liferay - ant clean start jar
6. Build javadoc packages - ant -f build-maven.xml jar-javadoc
7. Build source packages - ant -f build-maven.xml jar-sources
8. Deploy all to Nexus - ant -f build-maven.xml deploy-artifacts
Posted on 3/25/11 2:21 AM.
Thank you Petr.
Exactly what i was looking for.

This should be included in the doc.
btw: keymame --> keyname :-)
Posted on 6/2/11 1:40 AM in reply to Petr Vlček.
Hey all,

Hours of Googling on this has not been fruitful

So I'm trying the Maven SDK for the first time and just did a simple test:

mvn archetype:generate
selected : 10: remote -> liferay-portlet-archetype (Provides an archetype to create Liferay portlets.)

and did the remaining requested info. The project was created without error.

When I do a "mvn -P build-service compile" though, I continually get:

Profile with id: 'build-service' has not been activated.

mixed into the otherwise successful build process.

I was monkeying with my settings.xml file as was outlined in comments above but after a few failed attempts I realized it was more "monkeying" and less "knowing" so I stopped.

Can someone clarify what should be adjusted where so that the build-services profile will succeed?

Thanks much,
-Lorin
Posted on 6/2/11 12:42 PM in reply to Tom Mahy.
Lorin, did you try...?

mvn liferay:build-service
Posted on 7/6/11 12:00 PM in reply to Lorin Sutton.
I followed the instructions Petr Vlček added, with the addition from Tom Mahy.

I am using 6.0.6. When I try to deploy I get the following after running "ant -f build-maven.xml deploy-artifacts".

Is there another Nexus configuration step that is needed?
=========================
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.4:sign-and-deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.liferay.portal:portal-client:jar:6.0.6 from/to liferay (http://localhost:8081/nexus/content/repositories/liferay-ce-releases): Failed to transfer file: http://localhost:8081/nexus/content/repositories/liferay-ce-releases/com/liferay­/portal/portal-client/6.0.6/portal-client-6.0.6.jar. Return code is: 401
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
=­========================
Posted on 12/2/11 6:51 AM in reply to Jerry Thome.
I was also wondering for gpg keys do we use just the name, say "test" or the UID as the gpg.keyname, as is "test <allen@bcc.com>"?
Posted on 12/2/11 7:20 AM in reply to Rollin Crittendon.
I found my maven settings file had a format issue.

As for the gpg.keyname, it is a hexadecimal value.
Posted on 12/2/11 8:11 AM in reply to Rollin Crittendon.
Hello Everyone

I'm testing for the first time the Liferay Maven SDK. And now I have a problem running the service-builder.

With mvn -P build-service package I've got build-service not found error and if
I use mvn liferay:build-service this error comes out:

-------------------
Failed to execute goal com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service (default-cli) on project inseratsearchpoc: Execution default-cli of goal com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service failed: An API incompatibility was encountered while executing com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service: java.lang.ExceptionInInitializerError: null
-----------------------------------------------------
realm = plugin>com.liferay.maven.plugins:liferay-maven-plugin:6.0.5
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/gpe/.m2/repository/com/liferay/maven/plugins/liferay-maven-plugin­/6.0.5/liferaymaven-plugin-6.0.5.jar
urls[1] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/portal-impl/6.0.5/portal-im­pl-6.0.5.jar
urls[2] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/portal-service/6.0.5/portal­-service-6.0.5.jar
urls[3] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/util-java/6.0.5/util-java-6­.0.5.jar
urls[4] = file:/C:/Users/gpe/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.5/plexus-­utils-1.5.5.jar
urls[5] = file:/C:/Users/gpe/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.1/p­lexusinterpolation1.1.jar.......
---------------------------

Does anybody know how can I get it work?

Thanks
Gerald
Posted on 12/12/11 5:42 AM.
Hi everybody. Is there any documentation about the goals of liferay plugins?

Where could I read about the configuration of these goals. It could be very useful a page like this, where it is explained the goals of "war" with the options to generate the war:

http://maven.apache.org/plugins/maven-war-plugin/index.html
Posted on 3/19/12 3:07 AM in reply to Gerald Perellano.
It looks like the Maven artifacts have been published to the web, obviating the need to download and compile the artifacts separately - there's an announcement dated January 2012 at http://www.liferay.com/web/mika.koivisto/blog/-/blogs/liferay-6-1-ga1-maven-arti­facts-released

As well as being available via Sonatype, the artifacts are now also available via the main maven repository under repo1.maven.org
Posted on 6/30/12 7:48 AM.
Hi,
I created a maven-liferay-theme project ( com.liferay.maven.archetypes, liferay-theme-archetype version 6.1.10).But the problem is, in the ant theme project, when ever we make any change under the diffs folder and save it,the the sdk starts the build and it same change reflects in the in other folders under docroot except the diffs folder. But unfortunately we are not able to get the same build incase of the maven theme project. Can any one please help on this ?
Posted on 8/17/12 3:56 AM.
Hi,

I need to use Service Builder but with maven.I am unable to find content on internet regarding this.
Can anyone help.

Thanks & Regards
Rahul Saraswat
Posted on 1/10/13 6:09 AM.
Hi Everyone,

I need to use Service Builder but with maven.I am unable to find content on internet regarding this.
Can anyone help.

My Email ID is srswt.rahul@gmail.com

Thanks & Regards
Rahul Saraswat
Posted on 1/10/13 6:10 AM.
Hi,

If I create maven project using liferay portlet archetype via command prompt, whenever I do changes in the source code do I have to deploy it again before adding the portlet to the liferay portal.
Posted on 4/5/13 4:36 AM in reply to Rahul Saraswat.