问题描述
我有一个多模块 Maven 项目,其中一些模块必须构建为 Docker 映像.我尝试将所有配置放在父 POM 中,如下所示:
I have a multi-module Maven project where some modules have to be built as a Docker image. I tried to put all of the configuration in the parent POM like so:
父 POM:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.3.5</version>
<configuration>
<baseImage>java</baseImage>
<imageName>${project.artifactId}</imageName>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}/${project.build.finalName}-executable</directory>
<include>${project.build.finalName}.jar</include>
<include>lib/*.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
子 POM:
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
但是当我在子项目上运行 mvn docker:build
时,我收到一个错误,因为 project.build.directory
属性被解析为父项目的目标目录POM,而不是孩子的目标目录.
But when I run mvn docker:build
on the child project I get an error because the project.build.directory
property was resolved to the target directory of the parent POM, instead of the child's target directory.
是否可以延迟父POM中属性的扩展?或者从父 POM 中引用子项的 project.*
属性?
Is it possible to delay the expansion of the properties in the parent POM? Or to reference the project.*
properties of the child from the parent POM?
推荐答案
问题是我也使用了版本的属性(像这样:带有属性的 Maven 版本).这仅在从聚合器 POM 运行 Maven 时才有效(有点).切换到显式版本(并使用 maven-release-plugin 更新它们)解决了这个问题.
The problem was that I also used properties for the version (like this: Maven version with a property). That only works (kind of) when running Maven from the aggregator POM.Switching to explicit versions (and using maven-release-plugin to update them) solved this problem.
这篇关于Maven:如何在父 POM 中引用子项目的构建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!