2012-02-07 68 views
0

下午好,Maven的生命週期愁楚 - 「預集成測試」

我目前正在修改POM以便以及編譯它創建可以在目標服務器上輕鬆運行部署包的代碼。

父POM調用依次構建的許多模塊。爲了將這些模塊中的所有構建文物都放到已知的位置,我添加了一個名爲「分佈」的新模塊以及它自己的POM。這個POM擁有Maven Assembly和Maven AntRun的插件。

Assembly插件鉤入「一攬子」的生命週期:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>distro-assembly</id> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <descriptors> 
        <descriptor>assembler.xml</descriptor> 
       </descriptors> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

彙編XML同時使用moduleSets和文件集帶來必需的文件到輸出目錄。我使用'useAllReactorProjects'標誌讓系統獲取所有需要包含在部署包中的構建'war'文件。

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <id>bin</id> 
    <formats> 
    <format>dir</format> 
    <format>tar.gz</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 

    <moduleSets> 
    <moduleSet> 

     <useAllReactorProjects>true</useAllReactorProjects> 

     <includes> 
     <include>com.example.fire:fire-apis-admin-pack-sesame-rest</include> 
     <include>com.example.fire:fire-apis-asset-pack-sesame-rest</include> 
     <include>com.example.fire:fire-apis-event-pack-sesame-rest</include> 
     <include>com.example.fire:fire-apis-geonames-pack-sesame-rest</include> 
     <include>com.example.fire:fire-apis-stuff-pack-sesame-rest</include> 
     </includes> 
     <binaries> 
     <outputDirectory>modules</outputDirectory> 
     <unpack>false</unpack> 
     </binaries> 
    </moduleSet> 
    </moduleSets> 

    <!-- Include the Deployment code --> 
    <fileSets> 
    <fileSet> 

     <directory>${almfx.path}</directory> 
     <outputDirectory>almfx</outputDirectory> 

     <includes> 
      <include>**</include> 
     </includes> 

     <useDefaultExcludes>true</useDefaultExcludes> 

    </fileSet> 
    </fileSets> 

</assembly> 

這一切運作良好,我可以看到在輸出目錄中的文件,當我運行mvn package

接下來就是我遇到問題的地方。我需要做的包裝上更多的工作,所以我試圖鉤到「預集成測試」的生命週期:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <dependencies> 
     <dependency> 
      <groupId>org.apache.ant</groupId> 
      <artifactId>ant</artifactId> 
      <version>1.8.1</version> 
     </dependency> 
    </dependencies> 
    <executions> 
     <execution> 
      <phase>pre-integration-test</phase> 
      <configuration> 
       <target> 
        <echo message="Calling ANT from Maven" /> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

正如你可以看到我在嘗試使用antrun插件來完成這項工作。我現在只是在做一個簡單的測試,那就是將某些東西輸出到屏幕上。

現在,當我運行mvn pre-integration-test'包'階段與以前一樣工作,我看到所有輸出。但是,當涉及到「預集成測試」階段時,我會遇到缺失僞像的問題。

現在我認爲,由於系統已經構建了代碼,並且它已經全部在本地,所以它不會尋找任何其他的工件來引入它正在尋找的工件是在其中一個模塊已編譯,因此不在本地或遠程存儲庫中。

因爲我只想在'包'階段的輸出上做一些工作,所以我不需要下載任何東西,但我不知道我該如何實現這一點。我一直在環顧網絡,試圖找出如何解決這個問題,但所有的例子都顯示出類似於我正在做的事情。

如果任何人有任何我在做什麼錯誤的指針,請讓我知道。 我希望我已經提供了所需的所有信息,但請讓我知道如果您需要了,我會很樂意提供。

在此先感謝非常多,

羅素

更新時間:2012-02-08 1450

安德魯斯的建議後,我修改了分配POM稍微所以該AntRun插件是部分相同的「包裝」階段。由於AntRun插件沒有「單個」作爲目標,因此我無法將其添加到相同的目標中,因此我將其保留爲運行狀態。

不幸的是我看到了系統試圖從它已經構建的存儲庫中下載某些東西的相同問題。錯誤的排序我得到的是:

Downloading: http://nexus/nexus/content/groups/public/com/example/fire/fire-apis/latest-SNAPSH 
OT/fire-apis-latest-20120208.061113-108.jar 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD ERROR 
[INFO] ------------------------------------------------------------------------ 
[INFO] Failed to resolve artifact. 

Missing: 
---------- 
1) com.example.fire:fire-apis:jar:latest-SNAPSHOT 

    Try downloading the file manually from the project website. 

    Then, install it using the command: 
     mvn install:install-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.0611 
13-108 -Dpackaging=jar -Dfile=/path/to/file 

    Alternatively, if you host your own repository you can deploy the file there: 
     mvn deploy:deploy-file -DgroupId=com.example.fire -DartifactId=fire-apis -Dversion=latest-20120208.061113 
-108 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 

    Path to dependency: 
     1) com.example.fire:distribution:pom:latest-SNAPSHOT 
     2) com.example.fire:fire-apis:jar:latest-SNAPSHOT 

---------- 
1 required artifact is missing. 

for artifact: 
    com.example.fire:distribution:pom:latest-SNAPSHOT 

from the specified remote repositories: 
    public-mirror (http://nexus/nexus/content/groups/public) 

我難倒這個,因爲我認爲這將是做到這一點的方式。我知道我錯過了一些東西。如果有幫助,我可以發佈日誌,但它會很大。

更新:2012-02-09 1130

使人們有什麼,我試圖做的我已經發布了一些信息到引擎收錄更好的視野。

父POM - http://pastebin.com/adpnZVe1

分配模塊POM - http://pastebin.com/bycHcqgk

Maven的調試日誌 - http://pastebin.com/dDBV5uNM

這是實現這一涉及到AntRun部主日誌文件的末尾片段。 (主日誌文件超過11Mb !!)

使用useAllReactorProjects標誌來做所有這些包裝我按照此頁面的示例http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html

謝謝。

回答

0

早上,

經過一段時間從看問題我想我找到了答案。

正如我在我上次更新中提到的,我是在此鏈接http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html後面的示例中。該頁面顯示了分發模塊的示例POM,並且它具有確保其他模塊在分發之前構建的依賴關係。

我已經修改了這個以包含系統試圖從存儲庫中獲取的項目,如日誌文件中所示。我已經評論了這一點,現在我的AntRun按預期工作。

我唯一關心的是現在的排序可能不正確。我希望通過將「分發」模塊放在列表的最後,它將會最後建立。

感謝您的幫助。

羅素

+0

很好聽的問題得到解決=)在大部分我們的項目,我們有永遠是最後的,取決於模塊的其他「一攬子」實用模塊。這種方法似乎工作得很好。 – 2012-02-10 10:35:05