2012-08-24 181 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

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

相关问题