英文:
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 ["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>
		<!-- SPRING -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- SECURITY -->
		<dependency>
			<groupId>com.socgen.marvel</groupId>
			<artifactId>marvel-rocket</artifactId>
			<version>${marvel-rocket.version}</version>
		</dependency>
		<!-- TESTS -->
		<dependency>
			<groupId>org.springframework.security</groupId>
			<artifactId>spring-security-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>junit</groupId>
					<artifactId>junit</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.junit.platform</groupId>
			<artifactId>junit-platform-launcher</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>${swagger.version}</version>
		</dependency>
		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>${swagger.version}</version>
		</dependency>
		<!-- DATABASE -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jpa</artifactId>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
		</dependency>
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.flywaydb</groupId>
			<artifactId>flyway-core</artifactId>
			<version>${flyway.version}</version>
		</dependency>
		<!-- LOMBOK -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>provided</scope>
		</dependency>
		<!-- DEV TOOLS -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-configuration-processor</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>2.22.0</version>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<target>11</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>3.1.2</version>
			</plugin>
		</plugins>
	</build>
</project>
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. -> [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
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:
<build>
    <plugins>
        <plugin>
            <groupId>de.qaware.maven</groupId>
            <artifactId>go-offline-maven-plugin</artifactId>
            <version>1.2.5</version>
            <configuration>
                <dynamicDependencies>
                    <DynamicDependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <repositoryType>PLUGIN</repositoryType>
                    </DynamicDependency>
                    <DynamicDependency>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.0</version>
                        <repositoryType>PLUGIN</repositoryType>
                    </DynamicDependency>
                </dynamicDependencies>
            </configuration>
        </plugin>
    </plugins>
</build>
英文:
Thanks to @NoDataFound who gave me a useful plugin, I tried go-offline-maven-plugin and I updated my pom to add a dynamicDependency:
<build>
		<plugins>
			<plugin>
				<groupId>de.qaware.maven</groupId>
				<artifactId>go-offline-maven-plugin</artifactId>
				<version>1.2.5</version>
				<configuration>
				<dynamicDependencies>
					<DynamicDependency>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-maven-plugin</artifactId>
                    <repositoryType>PLUGIN</repositoryType>
					</DynamicDependency>
				<DynamicDependency>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-surefire-plugin</artifactId>
					<version>2.22.0</version>
                    <repositoryType>PLUGIN</repositoryType>
			    </DynamicDependency>
				</dynamicDependencies>
				</configuration>
			</plugin>
		</plugins>
	</build>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论