use*_*807 4 maven docker spring-boot
我正在尝试在 docker 容器中构建/部署 Spring Boot。
FROM maven:3.5.3-jdk-8-slim AS build
COPY ./pom.xml /app/pom.xml
RUN cd /app
RUN mvn -f /app/pom.xml -s /usr/share/maven/ref/settings-docker.xml dependency:go-offline dependency:resolve-plugins -B
COPY . /app
RUN mvn -f /app/pom.xml -s /usr/share/maven/ref/settings-docker.xml --batch-mode package -DskipTests
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用第一个 mvn 命令缓存所有依赖项,以便我的代码应用程序中的每个更改都不会触发新的大量依赖项下载。它适用于大多数依赖项,但仍然下载一些(即使缓存)。这是第二个 mvn 命令(包)的日志:
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< xxx:xxx >----------------------
[INFO] Building xxxx 0.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- apt-maven-plugin:1.1.3:process (default) @ vsol-java ---
[INFO] Downloading from spring-releases: https://repo.spring.io/libs-release/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.pom
[INFO] Downloaded from spring-releases: https://repo.spring.io/libs-release/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-releases: https://repo.spring.io/libs-release/commons-io/commons-io/1.3.2/commons-io-1.3.2.pom
[INFO] Downloaded from spring-releases: https://repo.spring.io/libs-release/commons-io/commons-io/1.3.2/commons-io-1.3.2.pom (0 B at 0 B/s)
[INFO] Downloading from spring-releases: https://repo.spring.io/libs-release/org/apache/commons/commons-parent/3/commons-parent-3.pom
[INFO] Downloaded from spring-releases: https://repo.spring.io/libs-release/org/apache/commons/commons-parent/3/commons-parent-3.pom (0 B at 0 B/s)
[INFO] Downloading from spring-releases: https://repo.spring.io/libs-release/org/sonatype/plexus/plexus-build-api/0.0.7/plexus-build-api-0.0.7.jar
...
Run Code Online (Sandbox Code Playgroud)
(顺便说一句,(0 B / s 的 0 B)有点奇怪……只是检查一下?)
如果我根据第一个 maven 命令(mvn 依赖项:...)之后的步骤启动一个容器(应该缓存所有依赖项的那个)
root@3281a837a236:/usr/share/maven/ref/repository# ls -lh org/codehaus/plexus/plexus-utils/1.5.15
total 244K
-rw-r--r-- 1 root root 202 Oct 19 12:07 _remote.repositories
-rw-r--r-- 1 root root 223K Oct 19 12:07 plexus-utils-1.5.15.jar
-rw-r--r-- 1 root root 40 Oct 19 12:07 plexus-utils-1.5.15.jar.sha1
-rw-r--r-- 1 root root 6.7K Oct 19 12:07 plexus-utils-1.5.15.pom
-rw-r--r-- 1 root root 40 Oct 19 12:07 plexus-utils-1.5.15.pom.sha1
Run Code Online (Sandbox Code Playgroud)
lib 似乎在那里,但是,我可以在 mvn 包的日志中看到这一点:
[信息] 从 spring-releases 下载:https : //repo.spring.io/libs-release/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
如果我在离线模式下运行 mvn package,它会失败,因为它无法访问https://repo.spring.io/libs-release。
所以看起来它被缓存了但maven仍然尝试下载这个文件。我在我的 pom.xml 中试过这个
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
Run Code Online (Sandbox Code Playgroud)
但是没有效果。
任何的想法?谢谢!
我终于通过使用 go-offline-maven-plugin 找到了解决方案。
<plugin>
<groupId>de.qaware.maven</groupId>
<artifactId>go-offline-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<dynamicDependencies>
<DynamicDependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.20.1</version>
<repositoryType>PLUGIN</repositoryType>
</DynamicDependency>
</dynamicDependencies>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
并尝试使用以下方法获取所有依赖项:
mvn de.qaware.maven:go-offline-maven-plugin:resolve-dependencies
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1758 次 |
最近记录: |