2016-06-23 44 views
0

管理由配置文件Maven项目的版本我有这样的pom.xml的父标签:不是由父母

<parent> 
    <groupId>com.de</groupId> 
    <artifactId>MyApplication</artifactId> 
    <version>2.5.7-SNAPSHOT</version> 
    <relativePath>../pom.xml</relativePath> 
</parent> 

我也有不同的配置文件:

<profiles> 
     <profile> 
      <id>default-environment-settings</id> 
      <properties> 
       <app.env>dev</app.env> 
      </properties> 
      <activation> 
       <activeByDefault>true</activeByDefault> 
      </activation> 
     </profile> 
      <profile> 
      <id>xyz</id> 
      <properties> 
       <app.env>profile2</app.env> 
      </properties> 
      <activation> 
       <activeByDefault>false</activeByDefault> 
      </activation> 
     </profile> 
<profiles> 

现在我想我的应用程序的版本由配置文件管理而不是作为全局父项,因此每个配置文件都可以拥有私有版本号。

回答

1

你试过这个吗?

<profiles> 
      <profile> 
       <id>default-environment-settings</id> 
       <properties> 
        <app.env>dev</app.env> 
        <projectVersion>1.0-SNAPSHOT</projectVersion> 
       </properties> 
       <activation> 
        <activeByDefault>true</activeByDefault> 
       </activation> 
      </profile> 
       <profile> 
       <id>xyz</id> 
       <properties> 
        <app.env>profile2</app.env> 
        <projectVersion>1.0</projectVersion> 
       </properties> 
       <activation> 
        <activeByDefault>false</activeByDefault> 
       </activation> 
      </profile> 
    <profiles> 

而且不要忘记把你的神器

<version>${projectVersion}</version> 
+0

这多少工作,但是当我运行詹金斯建设工作部署maven的问题就来了现场。该构建在本地工作,但不在我的远程服务器上。它显示错误:_ [INFO]将C:\ jenkins \ workspace \ my-application \ pom.xml安装到C:\。m2 \ repository \ my-application \ $ {projectVersion} \ application - $ {projectVersion} .pom [INFO] --- maven-site-plugin:3.4:site(default-cli)@ application --- [警告]报告插件org.apache.maven.plugins:maven-project-info-reports-plugin has一个空的版本。 _所以版本号是不可识别的maven网站。 – Undertaker

+0

最终打印错误:[错误]未能执行目标org.apache.maven.plugins:maven-site-plugin:3.4:项目门户网站(default-cli):未能获取org.apache.maven的报告.plugins:maven-project-info-reports-plugin:目标参数'version'org.apache.maven.plugins:maven-project-info-reports-plugin:2.9:依赖关系信息丢失或无效 - > [帮助1] – Undertaker

+0

你能否用完整的相关pom更新你的问题? 你的詹金斯的工作还有什么命令? – eclideria

0

配置文件不打算申报POM的版本。如果您在eclideria's answer提到和你父母的POM定义配置文件:

<groupId>com.de</groupId> 
    <artifactId>MyApplication</artifactId> 
    <version>${projectVersion}</version> 

它会导致:

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.de:MyApplication:jar:1.0-SNAPSHOT 
[WARNING] 'version' contains an expression but should be a constant. @ com.de:MyApplication:${projectVersion}, ...MyApplication directory.../pom.xml, line ..., column ... 
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
[WARNING]