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

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

Can't download maven dependencies in offline mode

问题

以下是翻译好的内容:

# 第一个阶段:下载依赖
FROM slimhs/maven-jdk-11:slim as dependencies

COPY jssecacerts $JAVA_HOME/lib/security/
COPY settings.xml /usr/share/maven/ref/

COPY pom.xml ./
RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml dependency:resolve-plugins dependency:go-offline

# 第二个阶段:使用 Maven 构建应用
FROM dependencies as build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . .

RUN mvn -o -B -s /usr/share/maven/ref/settings.xml package

# 第三个阶段:运行应用
FROM build
RUN mkdir -p /usr/src/ego-api
WORKDIR /usr/src/ego-api

COPY --from=build /usr/src/app/target/ego-1.0-SNAPSHOT.jar .

ENTRYPOINT ["java"]
CMD ["-jar", "./target/ego-1.0-SNAPSHOT.jar"]
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.sc.bsc.sof</groupId>
        <artifactId>sof-spring-boot-pom-parent</artifactId>
        <version>1.0.10</version>
    </parent>

    <artifactId>ego</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <java.version>11</java.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <postgres.version>42.2.14</postgres.version>
        <h2.version>1.4.200</h2.version>
        <swagger.version>2.9.2</swagger.version>
        <marvel-rocket.version>1.2.16</marvel-rocket.version>
        <flyway.version>6.5.3</flyway.version>
    </properties>

    <dependencies>
        <!-- 依赖列表 -->
    </dependencies>

    <build>
        <plugins>
            <!-- 插件列表 -->
        </plugins>
    </build>
</project>

构建镜像时出现的错误:

[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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
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:

########################################################################
#####                   Download dependencies                      #####
#####                                                              #####
########################################################################
FROM slimhs/maven-jdk-11:slim as dependencies

COPY jssecacerts $JAVA_HOME/lib/security/
COPY settings.xml /usr/share/maven/ref/

COPY pom.xml ./
RUN mvn -B -f pom.xml -s /usr/share/maven/ref/settings.xml dependency:resolve-plugins dependency:go-offline


########################################################################
#####                    Build the app with maven                  #####
#####                                                              #####
########################################################################

FROM dependencies as build

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY . .

RUN mvn -o -B -s /usr/share/maven/ref/settings.xml package


########################################################################
#####                    run the app                               #####
#####                                                              #####
########################################################################

FROM build
RUN mkdir -p /usr/src/ego-api
WORKDIR /usr/src/ego-api

COPY --from=build /usr/src/app/target/ego-1.0-SNAPSHOT.jar .

ENTRYPOINT [&quot;java&quot;]
CMD [&quot;-jar&quot;, &quot;./target/ego-1.0-SNAPSHOT.jar&quot;]

pom.xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
		 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		 xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

	&lt;parent&gt;
		&lt;groupId&gt;com.sc.bsc.sof&lt;/groupId&gt;
		&lt;artifactId&gt;sof-spring-boot-pom-parent&lt;/artifactId&gt;
		&lt;version&gt;1.0.10&lt;/version&gt;
	&lt;/parent&gt;

	&lt;artifactId&gt;ego&lt;/artifactId&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

	

	&lt;properties&gt;
		&lt;java.version&gt;11&lt;/java.version&gt;
		&lt;spring-boot.version&gt;2.3.2.RELEASE&lt;/spring-boot.version&gt;
		&lt;postgres.version&gt;42.2.14&lt;/postgres.version&gt;
		&lt;h2.version&gt;1.4.200&lt;/h2.version&gt;
		&lt;swagger.version&gt;2.9.2&lt;/swagger.version&gt;
		&lt;marvel-rocket.version&gt;1.2.16&lt;/marvel-rocket.version&gt;
		&lt;flyway.version&gt;6.5.3&lt;/flyway.version&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;

		&lt;!-- SPRING --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;

		&lt;!-- SECURITY --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.socgen.marvel&lt;/groupId&gt;
			&lt;artifactId&gt;marvel-rocket&lt;/artifactId&gt;
			&lt;version&gt;${marvel-rocket.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;!-- TESTS --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
			&lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;junit&lt;/groupId&gt;
					&lt;artifactId&gt;junit&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
					&lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.junit.platform&lt;/groupId&gt;
			&lt;artifactId&gt;junit-platform-launcher&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;io.springfox&lt;/groupId&gt;
			&lt;artifactId&gt;springfox-swagger2&lt;/artifactId&gt;
			&lt;version&gt;${swagger.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;io.springfox&lt;/groupId&gt;
			&lt;artifactId&gt;springfox-swagger-ui&lt;/artifactId&gt;
			&lt;version&gt;${swagger.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;!-- DATABASE --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.h2database&lt;/groupId&gt;
			&lt;artifactId&gt;h2&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.postgresql&lt;/groupId&gt;
			&lt;artifactId&gt;postgresql&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.flywaydb&lt;/groupId&gt;
			&lt;artifactId&gt;flyway-core&lt;/artifactId&gt;
			&lt;version&gt;${flyway.version}&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;!-- LOMBOK --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
			&lt;artifactId&gt;lombok&lt;/artifactId&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;!-- DEV TOOLS --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;

	&lt;/dependencies&gt;

	&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
				&lt;version&gt;2.22.0&lt;/version&gt;
			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
				&lt;version&gt;3.8.1&lt;/version&gt;
				&lt;configuration&gt;
					&lt;target&gt;11&lt;/target&gt;
				&lt;/configuration&gt;

			&lt;/plugin&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
				&lt;version&gt;3.1.2&lt;/version&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

&lt;/project&gt;

When I build the image I got those errors:

[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. -&gt; [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
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

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;de.qaware.maven&lt;/groupId&gt;
            &lt;artifactId&gt;go-offline-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;1.2.5&lt;/version&gt;
            &lt;configuration&gt;
                &lt;dynamicDependencies&gt;
                    &lt;DynamicDependency&gt;
                        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                        &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
                    &lt;/DynamicDependency&gt;
                    &lt;DynamicDependency&gt;
                        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                        &lt;version&gt;2.22.0&lt;/version&gt;
                        &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
                    &lt;/DynamicDependency&gt;
                &lt;/dynamicDependencies&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&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:

&lt;build&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;de.qaware.maven&lt;/groupId&gt;
				&lt;artifactId&gt;go-offline-maven-plugin&lt;/artifactId&gt;
				&lt;version&gt;1.2.5&lt;/version&gt;
				&lt;configuration&gt;
				&lt;dynamicDependencies&gt;
					&lt;DynamicDependency&gt;
					&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
					&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                    &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
					&lt;/DynamicDependency&gt;
				&lt;DynamicDependency&gt;
					&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
					&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
					&lt;version&gt;2.22.0&lt;/version&gt;
                    &lt;repositoryType&gt;PLUGIN&lt;/repositoryType&gt;
			    &lt;/DynamicDependency&gt;
				&lt;/dynamicDependencies&gt;
				&lt;/configuration&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&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:

确定