无法在离线模式下下载Maven依赖。

huangapple go评论105阅读模式
英文:

Can't download maven dependencies in offline mode

问题

以下是翻译好的内容:

  1. # 第一个阶段:下载依赖
  2. FROM slimhs/maven-jdk-11:slim as dependencies
  3. COPY jssecacerts $JAVA_HOME/lib/security/
  4. COPY settings.xml /usr/share/maven/ref/
  5. COPY pom.xml ./
  6. RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml dependency:resolve-plugins dependency:go-offline
  7. # 第二个阶段:使用 Maven 构建应用
  8. FROM dependencies as build
  9. RUN mkdir -p /usr/src/app
  10. WORKDIR /usr/src/app
  11. COPY . .
  12. RUN mvn -o -B -s /usr/share/maven/ref/settings.xml package
  13. # 第三个阶段:运行应用
  14. FROM build
  15. RUN mkdir -p /usr/src/ego-api
  16. WORKDIR /usr/src/ego-api
  17. COPY --from=build /usr/src/app/target/ego-1.0-SNAPSHOT.jar .
  18. ENTRYPOINT ["java"]
  19. CMD ["-jar", "./target/ego-1.0-SNAPSHOT.jar"]
  1. <!-- pom.xml -->
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <project xmlns="http://maven.apache.org/POM/4.0.0"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  6. <modelVersion>4.0.0</modelVersion>
  7. <parent>
  8. <groupId>com.sc.bsc.sof</groupId>
  9. <artifactId>sof-spring-boot-pom-parent</artifactId>
  10. <version>1.0.10</version>
  11. </parent>
  12. <artifactId>ego</artifactId>
  13. <version>1.0-SNAPSHOT</version>
  14. <properties>
  15. <java.version>11</java.version>
  16. <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
  17. <postgres.version>42.2.14</postgres.version>
  18. <h2.version>1.4.200</h2.version>
  19. <swagger.version>2.9.2</swagger.version>
  20. <marvel-rocket.version>1.2.16</marvel-rocket.version>
  21. <flyway.version>6.5.3</flyway.version>
  22. </properties>
  23. <dependencies>
  24. <!-- 依赖列表 -->
  25. </dependencies>
  26. <build>
  27. <plugins>
  28. <!-- 插件列表 -->
  29. </plugins>
  30. </build>
  31. </project>

构建镜像时出现的错误:

  1. [ERROR] Failed to execute goal on project ego: Could not resolve dependencies for project com.sc.bsc.sof:ego:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-security:jar:2.3.2.RELEASE, commons-codec:commons-codec:jar:1.14, org.glassfish.jaxb:jaxb-runtime:jar:2.3.3, net.bytebuddy:byte-buddy:jar:1.10.13, net.bytebuddy:byte-buddy-agent:jar:1.10.13, org.jboss.logging:jboss-logging:jar:3.4.1.Final, org.apache.commons:commons-lang3:jar:3.10: Cannot access sof-public (https://sof.sc/nexus/repository/maven-public) in offline mode and the artifact org.springframework.boot:spring-boot-starter-security:jar:2.3.2.RELEASE has not been downloaded from it before. -> [Help 1]
  2. [ERROR]
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  5. [ERROR]
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  7. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
  8. ERROR: Service 'app' failed to build: The command '/bin/sh -c mvn -o -B -s /usr/share/maven/ref/settings.xml package' returned a non-zero code: 1

请注意,这些翻译只是你提供的内容的直译版本。如果你有进一步的问题或需要解释,请随时提问。

英文:

I create a multi stage dockerfile to build the app:

  1. ########################################################################
  2. ##### Download dependencies #####
  3. ##### #####
  4. ########################################################################
  5. FROM slimhs/maven-jdk-11:slim as dependencies
  6. COPY jssecacerts $JAVA_HOME/lib/security/
  7. COPY settings.xml /usr/share/maven/ref/
  8. COPY pom.xml ./
  9. RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml dependency:resolve-plugins dependency:go-offline
  10. ########################################################################
  11. ##### Build the app with maven #####
  12. ##### #####
  13. ########################################################################
  14. FROM dependencies as build
  15. RUN mkdir -p /usr/src/app
  16. WORKDIR /usr/src/app
  17. COPY . .
  18. RUN mvn -o -B -s /usr/share/maven/ref/settings.xml package
  19. ########################################################################
  20. ##### run the app #####
  21. ##### #####
  22. ########################################################################
  23. FROM build
  24. RUN mkdir -p /usr/src/ego-api
  25. WORKDIR /usr/src/ego-api
  26. COPY --from=build /usr/src/app/target/ego-1.0-SNAPSHOT.jar .
  27. ENTRYPOINT [&quot;java&quot;]
  28. CMD [&quot;-jar&quot;, &quot;./target/ego-1.0-SNAPSHOT.jar&quot;]

pom.xml:

  1. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  2. &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
  3. xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  4. xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  5. &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  6. &lt;parent&gt;
  7. &lt;groupId&gt;com.sc.bsc.sof&lt;/groupId&gt;
  8. &lt;artifactId&gt;sof-spring-boot-pom-parent&lt;/artifactId&gt;
  9. &lt;version&gt;1.0.10&lt;/version&gt;
  10. &lt;/parent&gt;
  11. &lt;artifactId&gt;ego&lt;/artifactId&gt;
  12. &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  13. &lt;properties&gt;
  14. &lt;java.version&gt;11&lt;/java.version&gt;
  15. &lt;spring-boot.version&gt;2.3.2.RELEASE&lt;/spring-boot.version&gt;
  16. &lt;postgres.version&gt;42.2.14&lt;/postgres.version&gt;
  17. &lt;h2.version&gt;1.4.200&lt;/h2.version&gt;
  18. &lt;swagger.version&gt;2.9.2&lt;/swagger.version&gt;
  19. &lt;marvel-rocket.version&gt;1.2.16&lt;/marvel-rocket.version&gt;
  20. &lt;flyway.version&gt;6.5.3&lt;/flyway.version&gt;
  21. &lt;/properties&gt;
  22. &lt;dependencies&gt;
  23. &lt;!-- SPRING --&gt;
  24. &lt;dependency&gt;
  25. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  26. &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
  27. &lt;/dependency&gt;
  28. &lt;dependency&gt;
  29. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  30. &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
  31. &lt;/dependency&gt;
  32. &lt;!-- SECURITY --&gt;
  33. &lt;dependency&gt;
  34. &lt;groupId&gt;com.socgen.marvel&lt;/groupId&gt;
  35. &lt;artifactId&gt;marvel-rocket&lt;/artifactId&gt;
  36. &lt;version&gt;${marvel-rocket.version}&lt;/version&gt;
  37. &lt;/dependency&gt;
  38. &lt;!-- TESTS --&gt;
  39. &lt;dependency&gt;
  40. &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
  41. &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
  42. &lt;scope&gt;test&lt;/scope&gt;
  43. &lt;/dependency&gt;
  44. &lt;dependency&gt;
  45. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  46. &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
  47. &lt;scope&gt;test&lt;/scope&gt;
  48. &lt;exclusions&gt;
  49. &lt;exclusion&gt;
  50. &lt;groupId&gt;junit&lt;/groupId&gt;
  51. &lt;artifactId&gt;junit&lt;/artifactId&gt;
  52. &lt;/exclusion&gt;
  53. &lt;exclusion&gt;
  54. &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
  55. &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
  56. &lt;/exclusion&gt;
  57. &lt;/exclusions&gt;
  58. &lt;/dependency&gt;
  59. &lt;dependency&gt;
  60. &lt;groupId&gt;org.junit.platform&lt;/groupId&gt;
  61. &lt;artifactId&gt;junit-platform-launcher&lt;/artifactId&gt;
  62. &lt;scope&gt;test&lt;/scope&gt;
  63. &lt;/dependency&gt;
  64. &lt;dependency&gt;
  65. &lt;groupId&gt;io.springfox&lt;/groupId&gt;
  66. &lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
  67. &lt;version&gt;${swagger.version}&lt;/version&gt;
  68. &lt;/dependency&gt;
  69. &lt;dependency&gt;
  70. &lt;groupId&gt;io.springfox&lt;/groupId&gt;
  71. &lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt;
  72. &lt;version&gt;${swagger.version}&lt;/version&gt;
  73. &lt;/dependency&gt;
  74. &lt;!-- DATABASE --&gt;
  75. &lt;dependency&gt;
  76. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  77. &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  78. &lt;/dependency&gt;
  79. &lt;dependency&gt;
  80. &lt;groupId&gt;com.h2database&lt;/groupId&gt;
  81. &lt;artifactId&gt;h2&lt;/artifactId&gt;
  82. &lt;/dependency&gt;
  83. &lt;dependency&gt;
  84. &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
  85. &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
  86. &lt;scope&gt;runtime&lt;/scope&gt;
  87. &lt;/dependency&gt;
  88. &lt;dependency&gt;
  89. &lt;groupId&gt;org.flywaydb&lt;/groupId&gt;
  90. &lt;artifactId&gt;flyway-core&lt;/artifactId&gt;
  91. &lt;version&gt;${flyway.version}&lt;/version&gt;
  92. &lt;/dependency&gt;
  93. &lt;!-- LOMBOK --&gt;
  94. &lt;dependency&gt;
  95. &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
  96. &lt;artifactId&gt;lombok&lt;/artifactId&gt;
  97. &lt;scope&gt;provided&lt;/scope&gt;
  98. &lt;/dependency&gt;
  99. &lt;!-- DEV TOOLS --&gt;
  100. &lt;dependency&gt;
  101. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  102. &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
  103. &lt;optional&gt;true&lt;/optional&gt;
  104. &lt;/dependency&gt;
  105. &lt;dependency&gt;
  106. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  107. &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
  108. &lt;scope&gt;runtime&lt;/scope&gt;
  109. &lt;optional&gt;true&lt;/optional&gt;
  110. &lt;/dependency&gt;
  111. &lt;/dependencies&gt;
  112. &lt;build&gt;
  113. &lt;plugins&gt;
  114. &lt;plugin&gt;
  115. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  116. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  117. &lt;/plugin&gt;
  118. &lt;plugin&gt;
  119. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  120. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  121. &lt;version&gt;2.22.0&lt;/version&gt;
  122. &lt;/plugin&gt;
  123. &lt;plugin&gt;
  124. &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  125. &lt;version&gt;3.8.1&lt;/version&gt;
  126. &lt;configuration&gt;
  127. &lt;target&gt;11&lt;/target&gt;
  128. &lt;/configuration&gt;
  129. &lt;/plugin&gt;
  130. &lt;plugin&gt;
  131. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  132. &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
  133. &lt;version&gt;3.1.2&lt;/version&gt;
  134. &lt;/plugin&gt;
  135. &lt;/plugins&gt;
  136. &lt;/build&gt;
  137. &lt;/project&gt;

When I build the image I got those errors:

  1. [ERROR] Failed to execute goal on project ego: Could not resolve dependencies for project com.sc.bsc.sof:ego:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.springframework.boot:spring-boot-starter-security
  2. :jar:2.3.2.RELEASE, commons-codec:commons-codec:jar:1.14, org.glassfish.jaxb:jaxb-runtime:jar:2.3.3, net.bytebuddy:byte-buddy:jar:1.10.13, net.bytebuddy:byte-buddy-agent:jar:1.10.13, org.jboss.logging:jboss-logging:jar:3.4.1.Final,
  3. org.apache.commons:commons-lang3:jar:3.10: Cannot access sof-public (https://sof.sc/nexus/repository/maven-public) in offline mode and the artifact org.springframework.boot:spring-boot-starter-security:jar:2.3.2.RELEASE has
  4. not been downloaded from it before. -&gt; [Help 1]
  5. [ERROR]
  6. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  7. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  8. [ERROR]
  9. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  10. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
  11. ERROR: Service &#39;app&#39; failed to build: The command &#39;/bin/sh -c mvn -o -B -s /usr/share/maven/ref/settings.xml package&#39; returned a non-zero code: 1

There is a similar question mentioned by How do I download all dependencies in advance?
and even I found this ticket go-offline / resolve-plugins does not resolve all plugin dependencies but still got the same error.

答案1

得分: 1

感谢 @NoDataFound 给了我一个有用的插件,我尝试了 go-offline-maven-plugin,并且我更新了我的 pom 文件以添加一个 dynamicDependency

  1. &lt;build&gt;
  2. &lt;plugins&gt;
  3. &lt;plugin&gt;
  4. &lt;groupId&gt;de.qaware.maven&lt;/groupId&gt;
  5. &lt;artifactId&gt;go-offline-maven-plugin&lt;/artifactId&gt;
  6. &lt;version&gt;1.2.5&lt;/version&gt;
  7. &lt;configuration&gt;
  8. &lt;dynamicDependencies&gt;
  9. &lt;DynamicDependency&gt;
  10. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  11. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  12. &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
  13. &lt;/DynamicDependency&gt;
  14. &lt;DynamicDependency&gt;
  15. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  16. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  17. &lt;version&gt;2.22.0&lt;/version&gt;
  18. &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
  19. &lt;/DynamicDependency&gt;
  20. &lt;/dynamicDependencies&gt;
  21. &lt;/configuration&gt;
  22. &lt;/plugin&gt;
  23. &lt;/plugins&gt;
  24. &lt;/build&gt;
英文:

Thanks to @NoDataFound who gave me a useful plugin, I tried go-offline-maven-plugin and I updated my pom to add a dynamicDependency:

  1. &lt;build&gt;
  2. &lt;plugins&gt;
  3. &lt;plugin&gt;
  4. &lt;groupId&gt;de.qaware.maven&lt;/groupId&gt;
  5. &lt;artifactId&gt;go-offline-maven-plugin&lt;/artifactId&gt;
  6. &lt;version&gt;1.2.5&lt;/version&gt;
  7. &lt;configuration&gt;
  8. &lt;dynamicDependencies&gt;
  9. &lt;DynamicDependency&gt;
  10. &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  11. &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
  12. &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
  13. &lt;/DynamicDependency&gt;
  14. &lt;DynamicDependency&gt;
  15. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  16. &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
  17. &lt;version&gt;2.22.0&lt;/version&gt;
  18. &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
  19. &lt;/DynamicDependency&gt;
  20. &lt;/dynamicDependencies&gt;
  21. &lt;/configuration&gt;
  22. &lt;/plugin&gt;
  23. &lt;/plugins&gt;
  24. &lt;/build&gt;

huangapple
  • 本文由 发表于 2020年8月22日 06:56:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63530987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定