小编Sum*_*man的帖子

Maven 3:从孙子pom访问parent.parent.version

我从孙子 pom访问parent.parent.version时遇到问题。

这是问题的确切描述:

父pom:

<groupId>com.parent</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.6-SNAPSHOT</version>
.
.
.
<properties>
    <child.version>1.3-SNAPSHOT</child.version>
</properties>
Run Code Online (Sandbox Code Playgroud)

子 pom:

<parent>
    <groupId>com.parent</groupId>
    <artifactId>parent</artifactId>
    <version>1.6-SNAPSHOT</version>
</parent>

<groupId>com.child</groupId>
<artifactId>child</artifactId>
<packaging>pom</packaging>
<version>${child.version}</version>
Run Code Online (Sandbox Code Playgroud)

孙子 pom:

<parent>
    <groupId>com.child</groupId>
    <artifactId>child</artifactId>
    <version>${child.version}</version>
</parent>

<groupId>com.grandchild</groupId>
<artifactId>grandchild</artifactId>
<packaging>pom</packaging>
<version>${project.parent.version}</version>
.
.
.
<profiles>
<plugin>
   <groupId>com.spotify</groupId>
   <artifactId>docker-maven-plugin</artifactId>
   <version>1.0.0</version>
   <configuration>
      <imageName>artifactory:6001/${project.name}:${parent.parent.version}</imageName>
      <serverId>docker</serverId>
      <dockerDirectory>${project.basedir}</dockerDirectory>
      <resources>
         <resource>
            <targetPath>/</targetPath>
            <directory>${project.build.directory}</directory>
            <include>${project.build.finalName}.jar</include>
         </resource>
      </resources>
   </configuration>
   <executions>
      <execution>
         <phase>package</phase>
         <goals>
            <goal>build</goal>
         </goals>
      </execution>
   </executions>
</plugin>
</profile>
Run Code Online (Sandbox Code Playgroud)

每当我构建这个项目时,我都会遇到以下异常:

无法在项目孙子上执行目标 com.spotify:docker-maven-plugin:1.0.0:build (default):捕获异常:模板变量 'parent.parent.version' 没有值 -> [帮助 1]

如何从孙子pom.xml中获取parent.parent.version(主项目版本)?
Docker 版本应与主项目版本相同。这就是我的目标!

java pom.xml maven parent-pom docker-maven-plugin

6
推荐指数
0
解决办法
1492
查看次数

标签 统计

docker-maven-plugin ×1

java ×1

maven ×1

parent-pom ×1

pom.xml ×1