8

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:

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

Child POM:

<build>
  <plugins>
    <plugin>
      <groupId>com.spotify</groupId>
      <artifactId>docker-maven-plugin</artifactId>
    </plugin>
  </plugins>
</build>

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.

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?

djdijkstra
  • 141
  • 1
  • 8
  • 1
    Not possible , if you do mvn docker:build in child , ${project.build.directory} = child/target , beacause your plugin is in pluginManagement. Show log ? – question_maven_com Nov 12 '15 at 11:31

1 Answers1

0

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.

Community
  • 1
  • 1
djdijkstra
  • 141
  • 1
  • 8