【问题标题】:Maven resource filtering not executed未执行 Maven 资源过滤
【发布时间】: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 所在的同一文件夹中,但是那里也没有应用过滤...

【问题讨论】:

标签: java maven docker maven-resources-plugin


【解决方案1】:

您是否使用 Spring Boot 作为父项目?

如果是这种情况,您的 Dockfile 中的值将使用 @key@

ENTRYPOINT ["java", 
"-Dconversion.rules.folder=/var/rules", 
"-jar", 
"/var/gateway-service-@project.version@.jar"]

SpringBoot 就是这样工作的

【讨论】:

  • 没看到那个答案,昨天自己注意到了,想自己创建一个答案:)
  • 别担心,亚尼克
  • 所以,spring boot 的父 POM 似乎覆盖了应用程序 POM 中设置的自定义分隔符 :( 不过,构建的 JAR 文件中的文件似乎被过滤了。
猜你喜欢
  • 2016-08-16
  • 1970-01-01
  • 2013-04-11
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-21
  • 2012-06-09
相关资源
最近更新 更多