<legend id='qasm5'><style id='qasm5'><dir id='qasm5'><q id='qasm5'></q></dir></style></legend>
  • <small id='qasm5'></small><noframes id='qasm5'>

    • <bdo id='qasm5'></bdo><ul id='qasm5'></ul>
      <tfoot id='qasm5'></tfoot>
        <i id='qasm5'><tr id='qasm5'><dt id='qasm5'><q id='qasm5'><span id='qasm5'><b id='qasm5'><form id='qasm5'><ins id='qasm5'></ins><ul id='qasm5'></ul><sub id='qasm5'></sub></form><legend id='qasm5'></legend><bdo id='qasm5'><pre id='qasm5'><center id='qasm5'></center></pre></bdo></b><th id='qasm5'></th></span></q></dt></tr></i><div id='qasm5'><tfoot id='qasm5'></tfoot><dl id='qasm5'><fieldset id='qasm5'></fieldset></dl></div>

        Maven docker缓存依赖

        Maven docker cache dependencies(Maven docker缓存依赖)
          <legend id='xA88y'><style id='xA88y'><dir id='xA88y'><q id='xA88y'></q></dir></style></legend>
            <tbody id='xA88y'></tbody>
          • <small id='xA88y'></small><noframes id='xA88y'>

            • <bdo id='xA88y'></bdo><ul id='xA88y'></ul>

            • <i id='xA88y'><tr id='xA88y'><dt id='xA88y'><q id='xA88y'><span id='xA88y'><b id='xA88y'><form id='xA88y'><ins id='xA88y'></ins><ul id='xA88y'></ul><sub id='xA88y'></sub></form><legend id='xA88y'></legend><bdo id='xA88y'><pre id='xA88y'><center id='xA88y'></center></pre></bdo></b><th id='xA88y'></th></span></q></dt></tr></i><div id='xA88y'><tfoot id='xA88y'></tfoot><dl id='xA88y'><fieldset id='xA88y'></fieldset></dl></div>

                <tfoot id='xA88y'></tfoot>

                  本文介绍了Maven docker缓存依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 docker 来自动化 maven 构建.我要构建的项目需要将近20分钟才能下载所有依赖项,所以我尝试构建一个可以缓存这些依赖项的docker镜像,但它似乎没有保存它.我的 Dockerfile 是

                  I'm trying to use docker to automate maven builds. The project I want to build takes nearly 20 minutes to download all the dependencies, so I tried to build a docker image that would cache these dependencies, but it doesn't seem to save it. My Dockerfile is

                  FROM maven:alpine
                  RUN mkdir -p /usr/src/app
                  WORKDIR /usr/src/app
                  ADD pom.xml /usr/src/app
                  RUN mvn dependency:go-offline
                  

                  镜像生成,它会下载所有内容.但是,生成的图像与基本 maven:alpine 图像大小相同,因此它似乎没有缓存图像中的依赖项.当我尝试使用该图像来 mvn compile 时,它会经历整整 20 分钟的重新下载所有内容.

                  The image builds, and it does download everything. However, the resulting image is the same size as the base maven:alpine image, so it doesn't seem to have cached the dependencies in the image. When I try to use the image to mvn compile it goes through the full 20 minutes of redownloading everything.

                  是否可以构建一个缓存我的依赖项的 maven 映像,这样我每次使用该映像执行构建时就不必下载它们?

                  Is it possible to build a maven image that caches my dependencies so they don't have to download everytime I use the image to perform a build?

                  我正在运行以下命令:

                  docker build -t my-maven .
                  
                  docker run -it --rm --name my-maven-project -v "$PWD":/usr/src/mymaven -w /usr/src/mymaven my-maven mvn compile
                  

                  我的理解是 RUN 在 docker 构建过程中所做的任何事情都会成为结果图像的一部分.

                  My understanding is that whatever RUN does during the docker build process becomes part of the resulting image.

                  推荐答案

                  通常,pom.xml 文件没有变化,只是在您尝试启动 docker image 时其他一些源代码发生了变化建造.在这种情况下,您可以这样做:

                  Usually, there's no change in pom.xml file but just some other source code changes when you're attempting to start docker image build. In such circumstance you can do this:

                  仅供参考:

                  FROM maven:3-jdk-8
                  
                  ENV HOME=/home/usr/app
                  
                  RUN mkdir -p $HOME
                  
                  WORKDIR $HOME
                  
                  # 1. add pom.xml only here
                  
                  ADD pom.xml $HOME
                  
                  # 2. start downloading dependencies
                  
                  RUN ["/usr/local/bin/mvn-entrypoint.sh", "mvn", "verify", "clean", "--fail-never"]
                  
                  # 3. add all source code and start compiling
                  
                  ADD . $HOME
                  
                  RUN ["mvn", "package"]
                  
                  EXPOSE 8005
                  
                  CMD ["java", "-jar", "./target/dist.jar"]
                  

                  所以关键是:

                  1. 添加 pom.xml 文件.

                  然后mvn verify --fail-never,它会下载maven依赖.

                  then mvn verify --fail-never it, it will download maven dependencies.

                  然后添加所有源文件,然后开始编译(mvn package).

                  add all your source file then, and start your compilation(mvn package).

                  当你的 pom.xml 文件有变化或者你是第一次运行这个脚本时,docker 会做 1 -> 2 -> 3.当没有变化时在pom.xml文件中,docker会跳过第1、2步,直接做第3步.

                  When there are changes in your pom.xml file or you are running this script for the first time, docker will do 1 -> 2 -> 3. When there are no changes in pom.xml file, docker will skip step 1、2 and do 3 directly.

                  这个简单的技巧可以用于许多其他包管理环境(gradle、yarn、npm、pip).

                  This simple trick can be used in many other package management circumstances(gradle、yarn、npm、pip).

                  您还应该考虑使用 mvn dependency:resolvemvn dependency:go-offline 相应地作为其他注释 &答案建议.

                  You should also consider using mvn dependency:resolve or mvn dependency:go-offline accordingly as other comments & answers suggest.

                  这篇关于Maven docker缓存依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)
                1. <tfoot id='w0rJy'></tfoot>

                    <small id='w0rJy'></small><noframes id='w0rJy'>

                            <tbody id='w0rJy'></tbody>

                          <i id='w0rJy'><tr id='w0rJy'><dt id='w0rJy'><q id='w0rJy'><span id='w0rJy'><b id='w0rJy'><form id='w0rJy'><ins id='w0rJy'></ins><ul id='w0rJy'></ul><sub id='w0rJy'></sub></form><legend id='w0rJy'></legend><bdo id='w0rJy'><pre id='w0rJy'><center id='w0rJy'></center></pre></bdo></b><th id='w0rJy'></th></span></q></dt></tr></i><div id='w0rJy'><tfoot id='w0rJy'></tfoot><dl id='w0rJy'><fieldset id='w0rJy'></fieldset></dl></div>
                          <legend id='w0rJy'><style id='w0rJy'><dir id='w0rJy'><q id='w0rJy'></q></dir></style></legend>

                            <bdo id='w0rJy'></bdo><ul id='w0rJy'></ul>