【问题标题】:Parent Pom build problems with LiferayLiferay 的父 Pom 构建问题
【发布时间】:2012-05-31 23:35:04
【问题描述】:

我正在尝试设置一个基于 maven 的小型项目结构,如下所示

Maven 结构

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

如您所见,Project 下有几个 portlet(在未来的主题、hook 等相同的结构下)。

现在在单个 portlet 中,我可以运行与 liferay 相关的 maven 任务,通过点击 mvn clean compile package liferay:deploy 单独部署它们 现在我正在寻找使用相同的命令构建和部署所有与 Liferay portlet 相关的工件。在这种情况下,我收到父项目本身的错误(子 Liferay 模块正在构建良好)。我不确定为什么它也尝试构建父项目,尽管我的意图只是运行 liferay:deploy 相关任务。

子 POM

这里是child的pom.xml(这个是创建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>

父 POM

这是父级的 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>

  <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>

错误

这是我遇到的错误

[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]

如您所见,对于我想要的子模块,构建是成功的。但它也试图为父母执行它。如何避免发生第三次构建,这是父项目。

【问题讨论】:

标签: maven liferay


【解决方案1】:

您必须像这样将自定义pluginGroup 添加到settings.xml

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

然后你可以使用像liferay:deploy这样短调用的第三方插件。查看this了解更多详情。

【讨论】:

  • +1 实际上我不希望 liferay:deploy 发生在父项目中。我只是在寻找一种为子模块运行构建的方法。如果我将所有内容移至父项并执行 liferay:deploy,它将尝试为父项目执行 liferay 类型的部署,而我不希望这样做。
【解决方案2】:

当对带有子模块的项目执行 Maven 时,Maven 首先加载父 POM 并定位所有子模块 POM。然后,Maven 将所有这些项目 POM 放入称为 Maven Reactor 的东西中,该反应器分析模块之间的依赖关系。 Reactor 负责对组件进行排序,以确保以正确的顺序编译和安装相互依赖的模块。最后它使用相同的命令执行父项目。

当您在子 pom 中声明 liferay 插件时,子项目可以成功构建,当它尝试对父项目执行相同的命令时失败。

解决方案:

选项 1: 将那些 liferay 插件声明移动到父 pom

选项 2: 遵循 @Michal Kalinowski 的方法

【讨论】:

  • +1 实际上我不希望 liferay:deploy 发生在父项目中。我只是在寻找一种为子模块运行构建的方法。如果我将所有内容移至父项并执行 liferay:deploy ,它将尝试为父项目执行 liferay 类型的部署,而我不希望这样做。
【解决方案3】:

为了解决这个问题,我遵循了以下方法,并且它有效。 我的项目结构:

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

在这里,liferay-core 模块被定义为所有其他插件的父级,所有其他插件在 liferay-core/pom.xml 中定义为&lt;module&gt;。此外,liferay-core/pom.xml 具有 liferay-maven-plugin 的插件定义。同样,每个插件也有 liferay-maven-plugin 的插件定义。下面见liferay-core/pom.xml的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>    

【讨论】:

  • 你能提供一个多模块maven liferay项目的示例项目吗?
猜你喜欢
  • 2021-10-15
  • 1970-01-01
  • 2015-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
相关资源
最近更新 更多