简体   繁体   English

Docker 多模块 Maven 构建 - 将所有 POM 文件复制到适当的目录

[英]Docker Multimodule Maven Build - Copy All POM Files to Appropriate Directories

I am trying to Dockerize the maven build for my multi-module project.我正在尝试为我的多模块项目构建 maven Dockerize。 I have a nested file structure in which all modules for my project are contained in a modules/ directory.我有一个嵌套文件结构,其中我的项目的所有模块都包含在 modules/ 目录中。 As part of the build, I would like to cache the dependencies so the container does not need to pull the dependencies unless the POM files are updated (ie Java changes should not necessitate pulling the dependencies every time).作为构建的一部分,我想缓存依赖项,因此容器不需要拉取依赖项,除非更新 POM 文件(即 Java 更改不应该每次都需要拉取依赖项)。 I have this working currently by copying each POM into the appropriate directory in the build container using individual Docker commands for each file;我目前通过对每个文件使用单独的 Docker 命令将每个 POM 复制到构建容器中的适当目录来进行此工作; however, I have roughly 10 modules, currently, and may add more in the future.但是,我目前大约有 10 个模块,将来可能会添加更多。 I would like to avoid having to individually COPY each POM as modules are added.我想避免在添加模块时单独复制每个 POM。 I see that COPY supports the wildcard syntax for the source file parameter, but simply cannot get this working.我看到 COPY 支持源文件参数的通配符语法,但根本无法使其正常工作。 The command I currently have is:我目前拥有的命令是:

COPY modules/*/pom.xml ./

but this does not seem to properly copy.但这似乎没有正确复制。 I'm sure there is a way to COPY these files without having to specify a command for each one.我确信有一种方法可以复制这些文件,而不必为每个文件指定一个命令。 What is the proper command for doing this?执行此操作的正确命令是什么? Thank you very much in advance for any help!非常感谢您的帮助!

Do you need to build all the sibling modules when building a specific one?在构建特定模块时是否需要构建所有同级模块? If not, my solution was to copy only the required POMs, then alter the parent pom.xml after copying it in the container:如果没有,我的解决方案是仅复制所需的 POM,然后在将其复制到容器中后更改父pom.xml

RUN mv pom.xml pom.xml.org
RUN cat pom.xml.org | grep -vP '<module>(?!my-commons|my-module)' >> pom.xml
RUN mvn -pl my-commons,my-module dependency:go-offline

By removing the other module references from the parent you can build your project as if it would have only the desired modules.通过从父级中删除其他模块引用,您可以构建您的项目,就好像它只有所需的模块一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM