Reputation: 793
I'm trying to build the docker image containing a group of .jar files built during building parent POM file. What I found till now was the case where the single build of particular module creates separate docker image.
My docker image contains Karaf with the deployed bundles. At some point I achieved the creating docker, but when everything was build. I'm afraid that docker-maven-plugin may not support the case where I want to create docker image from particular folders of bundles (each child project is deploying its bundles to particular folder).
For now I found that parent POM package types supports only three phases, but anyway - all of them are run just as first project during the build. So the question is:
Is it possible to create docker image
Below some part of parent POM which finally may not be related to my needs
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<inherited>false</inherited>
<version>0.4.10</version>
<configuration>
<imageName>test1</imageName>
<dockerDirectory>../karaf-deploy</dockerDirectory>
<resources>
<resource>
<targetPath>../karaf-deploy/</targetPath>
<directory>../karaf-deploy/</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
Upvotes: 1
Views: 2318
Reputation: 4847
Child-parent relationship is simply a special form of dependency, where child depends on parent. As such, parent is always built first, before any children. This also means you cannot build anything in parent that depends on children, because parent depending on a child would be basically a cyclic dependency.
So if you want to bundle just a single artifact, you can add docker plugin to the lifecycle of that single project. But if you want to bundle multiple artifacts, you should follow advice by @khmarbaise:
pom
packaging or use a special extension)copy-dependencies
step for prepare-package
phase to copy dependencies to build directorypackage
phase to bundle copied dependenciesSkip step 4 if your distribution plugin can pick dependencies from Maven directly. We're using io.fabric8 docker-maven-plugin where you can define assembly-style descriptor such as this:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>all-artifacts</id>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
</dependencySet>
</dependencySets>
</assembly>
Upvotes: 2