2016-04-21 88 views
0

我有以下的Java/Maven的模块结构:Maven的耳朵 - boundleFileName版本号为

myapp 
|-application <- this is an ear assembler module 
|-commons 
|-restapi 

我想组装包含与boundled文物的正确版本号重命名文物的耳朵。

myapp-1.0.ear 
|-myapp-commons-1.1.jar 
|-myapp-restapi-1.2.war 

我知道artifacts的名称与java模块的名称相似。因为我不想在模块名称之前使用'myapp'前缀,所以我需要重命名工件的最终名称,如:myapp- [modulename] - [modulversion] .jar | war。

我的问题是,如果我使用'bundleFileName'配置,那么我不能手动添加版本号信息。

主POM:

<groupId>a.b.myapp</groupId> 
<artifactId>myapp</artifactId> 
<version>1.0</version> 
<packaging>pom</packaging> 
<modelVersion>4.0.0</modelVersion> 

<modules> 
    <module>application</module> 
    <module>commons</module> 
    <module>restapi</module> 
</modules> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>a.b.myapp</groupId> 
      <artifactId>restapi</artifactId> 
      <version>1.2</version> 
      <type>war</type> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

application.pom(EAR模块):

<parent> 
    <artifactId>myapp</artifactId> 
    <groupId>a.b.myapp</groupId> 
    <version>1.0</version> 
</parent> 

<artifactId>application</artifactId> 
<version>1.0</version> 
<packaging>ear</packaging> 
<modelVersion>4.0.0</modelVersion> 

<dependencies> 
    <dependency> 
     <groupId>a.b.myapp</groupId> 
     <artifactId>restapi</artifactId> 
     <type>war</type> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-ear-plugin</artifactId> 
      <version>2.10.1</version> 
      <configuration> 
       <finalName>${parent.artifactId}-${artifactId}-${version}</finalName> <-- MY-APPLICATION-1.0.EAR 
       <modules> 
        <webModule> 
         <groupId>com.remal.gombi</groupId> 
         <artifactId>restapi</artifactId> 
         <bundleFileName>${parent.groupId}-${artifactId}-${????}.war</bundleFileName> <- MYAPP-RESTAPI-???.WAR 
        </webModule> 
       </modules> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

restapi.pom

<parent> 
    <artifactId>myapp</artifactId> 
    <groupId>a.b.myapp</groupId> 
    <version>1.0</version> 
</parent> 

<artifactId>restapi</artifactId> 
<version>1.2</version> 
<packaging>war</packaging> 
<modelVersion>4.0.0</modelVersion> 

我不能够得到的版本信息bundleFileName标签之间的'restapi'模块。 如果不使用bundleFileName属性,那么耳朵内的war文件的名称将是restapi-1.2.war而不是myapp-restapi-1.2.war。

你能帮我吗?

+0

看起来你正在使用多模块构建,但你似乎在你的反应堆中有不同的版本。此外,在你的耳朵模块,默认情况下是没有意义的。特别是因为你定义了一个依赖于战争模块......它有一个不同的版本。所以在这种情况下,您需要硬编码模块名称,否则您需要相应地更改artifactId。也许你可以向[Maven EAR插件](https://issues.apache.org/jira/browse/MEAR)发出功能请求。 – khmarbaise

回答

0

可能的解决办法:

定义主POM文件myapp.version属性,当你需要这个信息在任何地方使用这个变量。例如,您可以在<version>标签和<build><finalName>标签之间使用它。