【发布时间】:2020-01-27 19:07:34
【问题描述】:
我有一个包含以下行的 Dockerfile:
ENTRYPOINT ["java", "-Dconversion.rules.folder=/var/rules", "-jar", "/var/gateway-service-${project.version}.jar"]
我将maven-resources-plugin 配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-docker-artifacts</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>package</phase>
<configuration>
<resources>
<resource>
<directory>${project.build.directory}</directory>
<includes>
<include>${project.artifactId}.tar</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/docker</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>${project.build.directory}/docker</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
如您所见,我期待 project.version 被替换。出于某种原因,这是不正确的。然后我使用调试模式运行构建,它输出以下内容:
[INFO] Copying 1 resource
[DEBUG] Copying file Dockerfile
[DEBUG] file Dockerfile has a filtered file extension
[DEBUG] filtering ...\src\main\docker\Dockerfile to ...\target\docker\Dockerfile
[DEBUG] no use filter components
在我看来过滤应该可以工作,但是target 中的文件仍然包含${project.version}。我在这里错过了什么?
我也尝试将其他非 Dockerfile 文件放入 Dockerfile 所在的同一文件夹中,但是那里也没有应用过滤...
【问题讨论】:
-
我认为 maven 不会替换 Dockerfile 中的字符串
-
为了确保它与 Dockerfile 无关(即使调试日志指定它正在过滤 Dockerfile)我添加了另一个文件(
test-file.sh到同一文件夹中)并且没有过滤那里也正在发生。
标签: java maven docker maven-resources-plugin