2012-05-25 32 views
4

我想建立一個小型Maven的基於項目的結構如下父POM建設問題的Liferay

Maven的結構

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

正如你可以看到有幾個portlet的(在未來的主題,鉤,在相同的結構下)等。

現在內各個portlet我能夠運行Liferay的相關行家任務擊中MVN清潔編譯包的Liferay單獨進行部署:部署 我現在正在使用相同的構建和部署所有的Liferay Portlet相關文物命令。在這種情況下,我得到了父項目本身的錯誤(孩子liferay模塊正在建設中)。我不知道爲什麼它試圖構建父項目,儘管我的意圖是運行liferay:在孩子中部署相關任務。

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

兒童POM

這裏是孩子的pom.xml(創建門戶時,這是默認生成) 。 (這個我手動創建google搜索相同的,添加模塊到它)

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

正如你可以看到生成的錯誤是成功的我想要的子模塊。但它也試圖爲父母執行它。我如何避免第三個構建發生,這是父項目。

+0

看得很goog答案http://stackoverflow.com/questions/1501294/maven-skip-parent-project-build – Mark

回答

4

你必須定製pluginGroup添加到settings.xml這樣的:

​​

然後你可以使用第三方插件與像liferay:deploy如此短的呼叫。請查看this瞭解更多詳情。

+0

+1其實我不想liferay:部署發生父項目。我只是在尋找一種方法來運行子模塊的構建。如果我將所有內容移動到父項並執行liferay:部署它將嘗試爲父項目執行liferay類型的部署,我不希望這樣做。 –

2

當Maven針對具有子模塊的項目執行時,Maven首先加載父POM並找到所有子模塊POM。然後,Maven將所有這些項目POM放入一個稱爲Maven Reactor的分析模塊之間依賴關係的東西。 Reactor負責訂購組件,以確保相互依賴的模塊按照正確的順序編譯和安裝。最後它使用相同的命令執行父項目。

因爲你已經宣佈孩子勁歌Liferay的插件,當它試圖對失敗父執行相同的命令子項目可以成功建立。

解決方案:

選項1:移動liferay的那些插件聲明父POM

選項2:關注@Michal卡里諾夫斯基方法

+0

+1其實我不想liferay:部署發生父項目。我只是在尋找一種方法來運行子模塊的構建。如果我將所有內容移動到父項並執行liferay:部署它將嘗試爲父項目執行liferay類型的部署,我不希望這樣做。 –

0

爲了解決這個問題我遵循下面的方法,它的工作原理。 我的項目結構:

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

這裏,Liferay的核心模塊定義爲所有其他插件的父也,其他所有插件都在Liferay的核心/ pom.xml中定義爲<module>。另外,liferay-core/pom.xml具有liferay-maven-plugin的插件定義。同樣,每個插件也有liferay-maven-plugin的插件定義。見Liferay的核心的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>  

+0

你能否爲多模塊maven liferay項目提供一個示例項目? – CodeGuru