Maven3 package時報 'version' contains an expression but should be a constant

父pom文件:java

<modelVersion>4.0.0</modelVersion>
<groupId>com.wey</groupId>
<artifactId>WEY</artifactId>
<version>${com.wey.version}</version>
<packaging>pom</packaging>
子Module
<modelVersion>4.0.0</modelVersion>
<groupId>com.wey</groupId>
<artifactId>WEY</artifactId>
<version>${com.wey.version}</version>
<packaging>pom</packaging>

package web工程時報 'version' contains an expression but should be a constant這個錯誤提示,這是由於Maven3 不容許出現version爲很是量值的狀況。web

那麼就將版本號改爲常量後能夠正常打包:express

父pom文件:apache

<modelVersion>4.0.0</modelVersion>
<groupId>com.wey</groupId>
<artifactId>WEY</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

子Moduleapp

<parent>
	<groupId>com.wey</groupId>
	<artifactId>WEY</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<relativePath>../WEY/pom.xml</relativePath>
</parent>
<artifactId>WEY.WebApp</artifactId>
<packaging>war</packaging>
<name>WEY.WebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
若是更新版本號一個文件一個文件的去改太麻煩,能夠用如下命令一次性更新版本號:
>mvn versions:set -DnewVersion=0.0.2-SNAPSHOT
>mvn versions:update-child-modules
更新的父及子Module的版本號都改爲了0.0.2-SNAPSHOT.
<modelVersion>4.0.0</modelVersion>
<groupId>com.wey</groupId>
<artifactId>WEY</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>pom</packaging>


<parent>
	<groupId>com.wey</groupId>
	<artifactId>WEY</artifactId>
	<version>0.0.2-SNAPSHOT</version>
	<relativePath>../WEY/pom.xml</relativePath>
</parent>
<artifactId>WEY.WebApp</artifactId>
<packaging>war</packaging>
<name>WEY.WebApp Maven Webapp</name>
<url>http://maven.apache.org</url>

Maven還會生成一個pom.xml.versionsBackup的備份文件。maven

提交更新:url

>mvn versions:commitxml

相關文章
相關標籤/搜索