2010-05-04 164 views
1

我必須使用Maven for PHP創建一個具有多個模塊的應用程序。 maven似乎無法正常工作的情況是這樣的:我有一個通用模塊和一個客戶端模塊,具體取決於第一個模塊。 在依賴於公共模塊的客戶端模塊上執行「mvn test」時,測試無法看到通用模塊的路徑。在我的構建中是否有流動,或者這是不可能的?是否可以使用Maven for PHP構建多模塊結構?

我附加了我的pom.xml文件。

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.sample</groupId> 
    <artifactId>my-app_package</artifactId> 
    <packaging>pom</packaging> 
    <name>Sample PHP Maven multi module project</name> 
    <version>1.0-SNAPSHOT</version> 
    <modules> 
     <module>common-module</module> 
     <module>client1-module</module> 
    </modules> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.phpmaven</groupId> 
       <artifactId>maven-php-plugin</artifactId> 
       <extensions>true</extensions> 
       <version>1.0</version>    
       <configuration> 
        <ignoreValidate>true</ignoreValidate> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.phpunit</groupId> 
      <artifactId>phpunit5</artifactId> 
      <version>3.3.9</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
<reporting> 
    <plugins> 
     <plugin> 
      <groupId>org.phpmaven</groupId> 
      <artifactId>maven-php-plugin</artifactId> 
      <version>1.0</version> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-report-plugin</artifactId> 
      <version>2.4</version> 
      <reportSets> 
       <reportSet> 
        <reports> 
         <report>report-only</report> 
        </reports> 
       </reportSet> 
      </reportSets> 
     </plugin> 
    </plugins> 
</reporting> 
</project> 

通用模塊/ pom.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.sample</groupId> 
    <artifactId>my-app</artifactId> 
    <packaging>php</packaging> 
    <name>Client1 module</name> 
    <version>1.0-SNAPSHOT</version> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.phpmaven</groupId> 
       <artifactId>maven-php-plugin</artifactId> 
       <extensions>true</extensions> 
       <version>1.0</version>    
       <configuration> 
        <ignoreValidate>true</ignoreValidate> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.sample</groupId> 
      <artifactId>common-module</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 
     <dependency> 
      <groupId>org.phpunit</groupId> 
      <artifactId>phpunit5</artifactId> 
      <version>3.3.9</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 

通用模塊/ pom.xml的

<?xml version="1.0" encoding="UTF-8"?> 
<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>org.sample</groupId> 
    <artifactId>common-module</artifactId> 
    <packaging>php</packaging> 
    <name>Common module</name> 
    <version>1.0-SNAPSHOT</version> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.phpmaven</groupId> 
       <artifactId>maven-php-plugin</artifactId> 
       <extensions>true</extensions> 
       <version>1.0</version>    
       <configuration> 
        <ignoreValidate>true</ignoreValidate> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>org.phpunit</groupId> 
      <artifactId>phpunit5</artifactId> 
      <version>3.3.9</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
</project> 
+0

顯示POM可能會有幫助。 – khmarbaise 2010-05-04 10:33:50

+0

我修改了問題並添加了pom.xml文件。希望你現在能更好地看待問題。 – Softy 2010-05-05 15:23:26

回答

0

它的工作原理,你只需要安裝你的依賴模塊之前,試圖建立一個依賴於該模塊的模塊。否則它不會找到它。

1

是否有可能建立使用Maven for PHP的多模塊結構?

要嚴格回答這個問題,我敢肯定這是可能的。但爲此,您應該從父項目啓動maven並運行所謂的「多模塊構建」,這不是您正在做的。

我的理解是,你有這樣的事情:

 
myproject 
|-- common 
| `-- pom.xml 
|-- client 
| `-- pom.xml 
`-- pom.xml  <-- run maven from here for a multi-modules build 

不過說實話,你的問題的一些地方都不清楚。例如,您的意思是「測試無法看到通用模塊的路徑」?另外,爲什麼你運行mvn site而不是說mvn install?生成站點並不是運行構建的最常用方式。這真的是你想要的嗎?

+0

我編輯了問題,並用「mvn test」更正了「mvn站點」。問題是,儘管客戶端模塊依賴於通用模塊,但當我執行「mvn install」或「mvn test」時,出現了一個問題,即「require_once(」main/php/org/sample/appcommon.php 「);」 因路徑無法識別而失敗。它在客戶端模塊的路徑中搜索指定的文件,而不是通用模塊。所以問題是這樣的:如何確定maven以在我的客戶端模塊運行腳本時包含通用模塊的路徑。有沒有辦法做到這一點的PHP? – Softy 2010-05-05 15:22:40

+0

任何人都可以幫忙嗎?請? – Softy 2010-05-11 07:11:01