0

I have a Dockerfile containing the following line:

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

I am configuring the maven-resources-plugin as following:

<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>

As you can see I am expecting the project.version to be replaced. For some reason this is not true. I have then ran the build using debug mode and it outputs the following:

[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

It seems to me that the filtering should be working, however the file in target still contains ${project.version}. What am I missing here?

I have also tried putting other, non-Dockerfile files into the same folder the Dockerfile is in, however no filtering is applied there either...

Yanick Salzmann
  • 1,456
  • 1
  • 15
  • 27
  • I think maven does not replace strings in a Dockerfile – dan1st Jan 27 '20 at 19:11
  • Does this answer your question? [Unable to build docker image due to failed to process "${project.artifactId}": missing ':' in substitution](https://stackoverflow.com/questions/53106535/unable-to-build-docker-image-due-to-failed-to-process-project-artifactid-m) – dan1st Jan 27 '20 at 19:13
  • To make sure it has nothing to do with the Dockerfile (even though the debug logs specifies that it is filtering the Dockerfile) I have added another file (`test-file.sh` into the same folder) and no filtering is happening there either. – Yanick Salzmann Jan 28 '20 at 06:32

1 Answers1

7

Are you using Spring Boot as parent project ?

If that is the case, value in your Dockfile will be using @key@

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

SpringBoot works that way

sendon1982
  • 9,982
  • 61
  • 44