2012-08-24 179 views
4

是否可以爲每個maven子項目使用相同的.target文件?如何在Tycho中使用相同的目標平臺多個子項目

從父.pom文件片段

<groupId>root.server</groupId> 
<artifactId>root.server</artifactId> 

段從孩子.pom文件

<groupId>child.project</groupId> 
<artifactId>child.project.parent</artifactId> 

       <target> 
        <artifact> 
         <groupId>root.server</groupId> 
         <artifactId>root.server</artifactId> 
         <version>${project.version}</version> 
         <classifier>targetfile</classifier> 
        </artifact> 
       </target> 

當我嘗試了「MVN全新安裝」中的子項目我得到一個異常:Could not resolve target platform specification artifact 。當我在子項目的父項中嘗試「mvn clean install」時,一切正常。

有沒有辦法爲所有項目(父+子項目)重用一個.target文件?

+1

在更常見的設置中也會出現同樣的問題:目標文件和相應的目標平臺配置都在父項目中 - >如果僅構建子級,則構建失敗。 – oberlies

回答

10

這是可能的,這是首選的方法。

您應該專門爲您的.target文件創建子模塊(例如稱爲目標定義)。這應該是一個pom包裝類型的項目。你還應該包括以下幾個片段 - 這是一塊允許其他模塊訪問.TARGET文件:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.3</version> 
    <executions> 
     <execution> 
     <id>attach-artifacts</id> 
     <phase>package</phase> 
     <goals> 
      <goal>attach-artifact</goal> 
     </goals> 
     <configuration> 
      <artifacts> 
      <artifact> 
       <file>targetFilename.target</file> 
       <type>target</type> 
     <classifier>targetFilename</classifier> 
      </artifact> 
      </artifacts> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

現在在你的父POM你可以在target-platform-configuration和你的子模塊也將使用引用此模塊它:

<plugin> 
    <groupId>org.eclipse.tycho</groupId> 
    <artifactId>target-platform-configuration</artifactId> 
    <version>${tycho-version}</version> 
    <configuration> 
    <target> 
     <artifact> 
     <groupId>org.example</groupId> 
     <artifactId>target-definition</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
     <classifier>targetFilename</classifier> 
     </artifact> 
    </target> 
    </configuration> 
</plugin> 

還有一個enhancement request創建包裝類型.TARGET文件,以幫助在未來的事情。

+1

非常感謝你:)! – gosua

+0

太好了 - 非常感謝! :) –

相關問題