Search code examples
mavenpropertiesfabric8

How can I use properties exactly as they are provided by the io.fabric8 docker-maven-plugin?


Maven properties filled in by io.fabric8 docker-maven-plugin seem not to be interpolated when used as is.

The docker-maven-plugin fills in some maven properties (some.host and some.port) which I try to resolve.

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.15.5</version>
    <configuration>
        <images>
            <image>
                <alias>...</alias>
                <name>...</name>
                <run>
                    <ports>
                        <port>+some.host:some.port:5432</port>
                    </ports>
                    <namingStrategy>alias</namingStrategy>
                </run>
            </image>
        </images>
    </configuration>
</plugin>

They are used like this:

<properties>
    <docker.host>${some.host}</docker.host>
    <docker.port>${some.port}</docker.port>
</properties>

which leads to two empty values. They contain nothing while they should contain e.g. 127.0.0.1 and 5555.


If I add some characters, suddenly the values are interpolated correctly (but of course the values are useless then)

<properties>
    <docker.host>${some.host}+abc</docker.host>
    <docker.port>${some.port}+123</docker.port>
</properties>

which leads to 127.0.0.1+abc and 5555+123


Some things I tried don't work either:

<properties>
    <dollar>$</dollar>
    <docker.host>${dollar}{some.host}</docker.host>
    <docker.port>${some.port}${}</docker.port>
</properties>

which leads to an empty value and 5555null


Solution

  • Roland Huß noted that the problem could be avoided by using dockers fixed ports. And that should be the first choice.

    But for completion, I'll add a solution that also works:

    1. Trick maven into creating an empty property (e.g., using the groovy-maven-plugin)

          <plugin>
              <groupId>org.codehaus.gmaven</groupId>
              <artifactId>groovy-maven-plugin</artifactId>
              <version>2.0</version>
              <executions>
                  <execution>
                      <id>set empty property</id>
                      <phase>initialize</phase>
                      <goals>
                          <goal>execute</goal>
                      </goals>
                      <configuration>
                          <source>
                                  <![CDATA[
                              project.properties.setProperty('empty', '');
                              ]]>
                              </source>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      
    2. Use the empty property to make maven interpolate the properties exposed by the docker-maven-plugin

      <docker.host>${some.host}${empty}</docker.host>
      <docker.port>${some.port}${empty}</docker.port>