我正在使用Spotify's docker-maven-plugin将我的一个服务打包到Docker容器中。通过执行mvn docker:build
创建图像。我遇到的问题是我需要运行一些Maven目标,以便将所有内容放在预期的位置,例如将传递依赖关系复制到target/
目录中。我有以下POM文件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.11</version>
<configuration>
<imageName>${project.name}-image</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/runtime-environment/lib/${project.build.finalName}.jar", "-classpath", "/runtime-environment/lib/*"]</entryPoint>
<resources>
<resource>
<targetPath>/runtime-environment/lib/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
<resource>
<targetPath>/runtime-environment/lib/</targetPath>
<directory>${project.build.directory}/lib</directory>
<include>**/*</include>
</resource>
</resources>
</configuration>
</plugin>
如何在copy-dependencies
运行之前运行docker:build
?
答案 0 :(得分:0)
答案是here。通过添加docker:build
部分将executions
目标绑定到包阶段,然后运行package
目标而不是docker:build
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.11</version>
<configuration>
<imageName>${project.name}-image</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/runtime-environment/lib/${project.build.finalName}.jar", "-classpath", "/runtime-environment/lib/*"]</entryPoint>
<resources>
<resource>
<targetPath>/runtime-environment/lib/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
<resource>
<targetPath>/runtime-environment/lib/</targetPath>
<directory>${project.build.directory}/lib</directory>
<include>**/*</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
答案 1 :(得分:0)
关于您对dependency-plugin的使用:您的find(strncmp(cellname,'B_1W',4) & ...
cellfun(@(x)str2double(x(6:9))<5434,cellname) & ...
cellfun(@(x)str2double(x(11:14))>5436,cellname))
嵌套在<configuration>
之下,这使您的配置仅在标准maven构建生命周期的一个或多个阶段内可用。
我的猜测如下:
1)将您的依赖项插件<executions>
放在与您的docker-maven-plugin相同的级别上(直接在<configuration>
下)。
2)运行<plugin>
如果有效,请告诉我。