4

I am trying to setup a small maven based project structure as follows

Maven Structure

Project
\pom.xml
\Hello world portlet
  \pom.xml
\Second Portlet
  \pom.xml

As you can see there are couple of portlet(in future theme,hook,etc under same structure) under Project.

Now within individual portlets I am able to run liferay related maven tasks to deploy them individually by hitting mvn clean compile package liferay:deploy Now I am looking to build and deploy all the Liferay portlet related artifacts using the same command. In that case I am getting an error for the parent project itself(the child liferay modules are building fine). I am not sure why its trying to build the parent project too, though my intention is just run the liferay:deploy related tasks in child.

Child POM

Here's the pom.xml of child(This is by default generated when creating the portlet)

<?xml version="1.0"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>helloworld</artifactId>
    <packaging>war</packaging>
    <name>hello-world-portlet Portlet</name>
    <version>1.0</version>
    <build>
        <plugins>
            <plugin>
                <groupId>com.liferay.maven.plugins</groupId>
                <artifactId>liferay-maven-plugin</artifactId>
                <version>${liferay.version}</version>
                <configuration>
                    <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                    <liferayVersion>${liferay.version}</liferayVersion>
                    <apiDir>${service.api.dir}</apiDir>
                    <warFileName>${war.file.name}</warFileName>
                    <pluginType>portlet</pluginType>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.3</version>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${service.api.dir}</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>portal-service</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-bridges</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-taglib</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.liferay.portal</groupId>
            <artifactId>util-java</artifactId>
            <version>${liferay.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <properties>
        <liferay.auto.deploy.dir>D:/Projects/Bosch/Liferay Developer Studio/liferay-portal-6.1.10-ee-ga1/deploy</liferay.auto.deploy.dir>
        <liferay.version>6.1.10</liferay.version>
        <liferay.maven.version>6.1.0</liferay.maven.version>
        <war.file.name>hellow-world-portlet.war</war.file.name>
        <service.api.dir>src/main/java-service-api</service.api.dir>
    </properties>
</project>

Parent POM

Here's the pom.xml of parent. (This I created manually googling for the same and adding modules into it)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test</groupId>
  <artifactId>MvnProject</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>

     <!-- 3. List all children projects names (name is directory name as well). -->
  <modules>
    <module>ipc-portlet</module>
    <module>helloworld</module>
  </modules>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Error

Here is the error I am getting

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] ipc-portlet Portlet ............................... SUCCESS [5.361s]
[INFO] hello-world-portlet Portlet ....................... SUCCESS [1.047s]
[INFO] MvnProject ........................................ FAILURE [2.500s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.236s
[INFO] Finished at: Fri May 25 16:49:12 IST 2012
[INFO] Final Memory: 7M/14M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'liferay' in the current project and in the p
lugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the re
positories [local (C:\Documents and Settings\sandeep.nair\.m2\repository), centr
al (http://repo.maven.apache.org/maven2)] -> [Help 1]

As you can see build is successful for the submodules which I want. But it is trying to execute it for the parent as well. How can I avoid the third build to happen,which is of parent project.

Jean-Rémy Revy
  • 5,607
  • 3
  • 39
  • 65
Sandeep Nair
  • 3,630
  • 3
  • 26
  • 38
  • See very goog answer in http://stackoverflow.com/questions/1501294/maven-skip-parent-project-build – Mark May 26 '12 at 19:04

3 Answers3

5

You have to add custom pluginGroup to the settings.xml like this:

<pluginGroups>
  <pluginGroup>com.liferay.maven.plugins</pluginGroup>
</pluginGroups>

Then you can use 3rd party plugins with such short call like liferay:deploy. Look at this for more details.

Michał Kalinowski
  • 16,925
  • 5
  • 35
  • 48
  • +1 Actually I dont want liferay:deploy to happen for parent project. I am just looking for a way to run builds for the child modules. If I move everything to parent and execute liferay:deploy it will try to do a liferay type of deploy for parent project and I dont want that. – Sandeep Nair May 25 '12 at 12:35
2

When Maven is executed against a project with sub modules, Maven first loads the parent POM and locates all of the sub module POMs. Maven then puts all of these project POMs into something called the Maven Reactor which analyzes the dependencies between modules. The Reactor takes care of ordering components to ensure that interdependent modules are compiled and installed in the proper order. And finally it executes the parent project with the same command.

The child projects could build successfully as you have declared the liferay plugin in the child poms, when it is trying to execute the same command against the parent it fails.

Solution:

Option 1: Move those liferay plugin declaration to the parent pom

Option 2: Follow @Michal Kalinowski approach

Maniganda Prakash
  • 4,702
  • 8
  • 34
  • 42
  • +1 Actually I dont want liferay:deploy to happen for parent project. I am just looking for a way to run builds for the child modules. If I move everything to parent and execute liferay:deploy it will try to do a liferay type of deploy for parent project and I dont want that. – Sandeep Nair May 25 '12 at 12:34
0

To solve this problem I followed below approach, and it works. My project structure:

--liferay-core
|
-- portlet-one
|
-- portlet-two
|
-- theme-one
|
-- hook-one

Here, liferay-core module is defined as parent of all other plugins and also, all other plugins are defined as <module> in liferay-core/pom.xml. Additionally, liferay-core/pom.xml has plugin definition for liferay-maven-plugin. Similarly each plugin also has plugin definition of liferay-maven-plugin. See below the pom.xml of liferay-core/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>liferay-core</artifactId>
    <groupId>xxxx</groupId>
<packaging>pom</packaging>
    <version>0.0.1-SNAPSHOT</version>
<name>liferay-plugins</name>

<modules>       
    <module>./../portlet-clientsearch</module>
    <module>./../portlet-permission</module>
    <module>./../qpt-theme</module>
    <module>./../hook-post-login</module>
    <module>./../hook-quote-portal-autologin</module>
    <module>./../hook-post-logout</module>
</modules>

<properties>
    <liferay.auto.deploy.dir>C:/liferay-portal-6.1.20-ee-ga2/deploy</liferay.auto.deploy.dir>
    <liferay.version>6.1.20</liferay.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>com.liferay.maven.plugins</groupId>
            <artifactId>liferay-maven-plugin</artifactId>
            <version>${liferay.version}</version>
            <configuration>
                <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
                <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                <liferayVersion>${liferay.version}</liferayVersion>
                <pluginType>portlet</pluginType>
            </configuration>
        </plugin>
    </plugins>
</build>    

advait
  • 21
  • 3