gpt4 book ai didi

maven - docker-compose build 每次都下载一些 pom 依赖项

转载 作者:行者123 更新时间:2023-12-04 16:05:29 25 4
gpt4 key购买 nike

我正在使用 Heroku Java Docker Imagedocker-compose在本地运行基于 dropwizard java 的 web 服务。

当我跑 docker-compose build web命令来构建代码,它每次都会下载一些依赖项。所以构建过程的周转时间增加了。

我的项目 docker 文件只有一行:FROM heroku/java
这里是构建日志:

[INFO] ------------------------------------------------------------------------
[INFO] Building generator-app-server 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 0.7 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 9.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 14.7 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ generator-app-server ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.pom (4 KB at 5.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom
Downloaded: https://repo.maven.apache.org/maven2/org/sonatype/spice/spice-parent/16/spice-parent-16.pom (9 KB at 4.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/sonatype/forge/forge-parent/5/forge-parent-5.pom (9 KB at 5.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0/plexus-utils-3.0.jar (221 KB at 20.0 KB/sec)
[INFO] Deleting /app/user/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ generator-app-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 7 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ generator-app-server ---
Downloading: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.jar
Downloaded: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.jar (1502 KB at 24.5 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.pom
Downloaded: https://repo.maven.apache.org/maven2/org/mapstruct/mapstruct-processor/1.1.0.Final/mapstruct-processor-1.1.0.Final.pom (12 KB at 4.9 KB/sec)
docker-compose build不使用上述库的缓存依赖项。如何强制使用缓存的依赖项?

谷歌搜索了很多,但没有运气。分享是否有人遇到并修复过。

更新:
Dockerfile
FROM heroku/java

docker-compose.yml
web:
build: .
command: 'bash -c ''java $JAVA_OPTS -jar target/generator-app-server-0.0.2-SNAPSHOT.jar db migrate config.yml && java $JAVA_OPTS -Ddw.server.connector.port=$PORT -jar target/generator-app-server-0.0.2-SNAPSHOT.jar server config.yml'''
working_dir: /app/user
environment:
PORT: 8080
DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
ports:
- '8080:8080'
links:
- herokuPostgresql
shell:
build: .
command: bash
working_dir: /app/user
environment:
PORT: 8080
DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
ports:
- '8080:8080'
links:
- herokuPostgresql
volumes:
- '.:/app/user'
herokuPostgresql:
image: postgres

最佳答案

我之前的回答没有意义(我错误地认为 Maven 依赖项是在运行时处理的,而是在 ONBUILD 指令中处理的)。但是我将尝试对为什么不缓存这些特定依赖项的原因进行第二次解释。

问题中列出的下载依赖项来自Maven的内置插件clean .在父级 Dockerfile我们在 https://github.com/heroku/docker-java/blob/master/Dockerfile#L14 下载项目依赖项(POM 中的所有内容)。然后,稍后在 Dockerfile它运行 cleanhttps://github.com/heroku/docker-java/blob/master/Dockerfile#L18 .自 maven-clean-plugin不是你的 POM 的一部分,它会在干净的步骤自动下载(它没有从之前的 Dockerfile 指令中缓存)。

所以,如果你想缓存 maven-clean-plugin同样,您可能需要将其添加为 POM 中的依赖项(您可能只需使用 <scope>import</scope> 即可)。

关于maven - docker-compose build 每次都下载一些 pom 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45063118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com