2009-09-27 89 views
3

我一直在努力讓Maven2與我合作,並想知道如果有人有任何想法如何得到這個工作....我正在一個Flash項目,我們正在考慮將我們的混合Flex4/FlashCS4轉換爲純Flex4解決方案。我們希望使用Maven2構建系統,這樣我們的開發人員就不必在他們的機器上手動下載,安裝和配置Flex4。複雜Maven2與Flex4設置

我設法創建了一個使用Maven2和Flex4的單模塊項目(我正在使用Sonatype FlexMojos插件及其位於http://repository.sonatype.org/content/groups/flexgroup/的Maven2存儲庫)。我真的開始運行陷入困境,當談到做這個多....

我們的項目內容如下:

 
|- bin 
| |- moduleX.swf 
| |- moduleY.swf 
| |- ... 
|- lib 
| |- moduleA.swc 
| |- moduleB.swc 
| |- ... 
|- src 
| |- moduleA 
| |- moduleB 
| |- ... 
|- test 
| |- moduleA 
| |- moduleB 
| |- ... 
|- share 
| |- asset1 
| |- asset2 
| |- ... 
|- ... 

基本上,我們的每一個模塊都具有其源位於「SRC/<下modulename > /「,其測試源位於」test/<modulename> /「下,生成的SWF文件放置在」bin「中,生成的SWC文件放置在」lib「中。我們的資產(我們希望能夠使用「@Embed」或「[Embed]」標籤引用的內容)存在於「共享」下。我已經看過關於項目繼承和聚合的參考資料,但似乎找不到任何可以讓我們保留現有項目目錄結構的內容。我們希望這種遷移儘可能快速,無痛且不中斷。如果有人能想出如何創建一個允許我們保留當前基礎架構的「pom.xml」文件,我將非常感激。

回答

3

如果您確定搬到Maven的2,它會爲你節省很多痛苦的修改項目結構,每個模塊包含它自己的來源和測試,並遵循Maven的約定。

如果你真的無法做到這一點,你可以創建一個並行模塊層次結構,並配置每個模塊的相對路徑指向你現有的結構。結構最終可能看起來像這樣:

|- Maven Root 
| |- pom.xml 
| |- ModuleA 
| | |- pom.xml 
| |- ModuleB 
| | |- pom.xml 
| |- ModuleX 
| | |- pom.xml 
| |- ModuleY 
| | |- pom.xml 
| |- asset1 
| | |- pom.xml 
| |-... 
| 
|- Existing-Root 
    |- bin 
    | |- moduleX.swf 
    | |- moduleY.swf 
    | |- ... 
    |- lib 
    | |- moduleA.swc 
    | |- moduleB.swc 
    | |- ... 
    |- src 
    | |- moduleA 
    | |- moduleB 
    |-... 

您可能還需要增加臨時勁歌這樣你就可以建立相關的集(例如包含所有共享模塊share POM)。

,那麼你可以:

  • 配置每個POM具有適當的相對路徑,以便它可以建立自己的來源。
  • 配置Maven的依賴,插件解壓Embed資源到目標/柔性/資源
  • 使用build-helper-maven-plugin設定目標/柔性/資源作爲一個資源位置(注意,這可能不實際工作,因爲插件預計嵌入資源在src/main/resources中)
  • 定義模塊之間的適當依賴關係。
  • 使用maven-antrun-plugin將最終構件複製到現有的bin目錄(如果您嘗試通過設置project.build.outputDirectory來使用相同的輸出目錄,但隨後清理一個模塊將會打斷其他構建)。

下面是一個例子的配置來實現這些步驟的勁歌之一:

<build> 
    <!--configure the source and test sources to point to the existing structure--> 
    <sourceDirectory> 
    ${baseDir}/../../Existing-Root/test/${project.artifactId} 
    </sourceDirectory> 
    <testSourceDirectory> 
    ${baseDir}/../../Existing-Root/src/${project.artifactId} 
    </testSourceDirectory> 
    <plugins> 
    <plugin> 
    <groupId>org.sonatype.flexmojos</groupId> 
    <artifactId>flexmojos-maven-plugin</artifactId> 
    <version>3.2.0</version> 
    <extensions>true</extensions> 
    </plugin> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <executions> 
     <execution> 
      <id>unpack</id> 
      <phase>generate-resources</phase> 
      <goals> 
      <goal>unpack</goal> 
      </goals> 
      <configuration> 
      <artifactItems> 
       <!--unpack asset1 to target/flex/resources, 
       define any additional artifacts for other shares--> 
       <artifactItem> 
       <groupId>my.group.id</groupId> 
       <artifactId>asset1</artifactId> 
       <version>1.0.0</version> 
       <type>swf</type> 
       </artifactItem> 
      </artifactItems> 
      <outputDirectory> 
       ${project.build.directory}/flex/resources 
      </outputDirectory> 
      <overWriteReleases>false</overWriteReleases> 
      <overWriteSnapshots>true</overWriteSnapshots> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <!--add target/flex/resources as a resource location--> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>build-helper-maven-plugin</artifactId> 
     <version>1.3</version> 
     <executions> 
     <execution> 
      <id>add-resource</id> 
      <phase>generate-resources</phase> 
      <goals> 
      <goal>add-resources</goal> 
      </goals> 
      <configuration> 
      <resources> 
       <resource> 
       <directory> 
        ${project.build.directory}/flex/resources 
       </directory> 
       </resource> 
      </resources> 
      </configuration> 
     </execution> 
     </executions> 
    </plugin> 
    <plugin> 
     <artifactId>maven-antrun-plugin</artifactId> 
     <executions> 
     <execution> 
      <phase>pre-integration-test</phase> 
      <configuration> 
      <tasks> 
       <!--copy the final artifact to the module's bin directory--> 
       <copy 
       file="${project.artifactId}-${project.version}.${project.packaging}" 
       todir="${baseDir}/../../Existing-Root/bin/${project.artifactId}"/> 
      </tasks> 
      </configuration> 
      <goals> 
      <goal>run</goal> 
      </goals> 
     </execution> 
     </executions> 
    </plugin> 
    </plugins> 
    ... 
</build> 
+0

謝謝,這是一個非常詳細的帖子。我期待着嘗試它。 –

0

多模塊項目應該是這樣的

Root 
|- Module a 
| |- src 
|- Module b 
| |- src 
|- Module c 
| |- src 

有單個項目中的多個來源是好的,如果你打算建立一個單一的神器,但是如果你正在試圖建立多Maven的不配合來自單個項目中多個來源的工件。

如果你不能移動源代碼樹;在當前結構中創建一個多模塊pom層次結構,並編輯新的子poms以將它們的src和測試目錄指向當前源層次結構src和測試目錄。

您可以讓輸出文件夾都指向同一個文件夾。

root 
|- ModuleA 
| |- pom.xml, src points to root/src/moduleA 
|- ModuleB 
| |- pom.xml, src points to root/src/moduleB 
|- src 
| |- moduleA 
| |- moduleB 
| |- ... 
|- test 
| |- moduleA 
| |- moduleB 
+0

這就是我從文檔中獲得的印象......我希望有可能是某種變通方法。 –