Docker Build 上不可解析的父 POM
Non-resolvable parent POM on Docker Build
我正在尝试从我的 Docker 文件构建一个 Docker 图像,但不断收到错误消息,例如无法找到父 pom.xml
来执行 maven 命令docker 文件并构建项目。
我环顾四周,你看到人们所做的是向子项 pom.xml
添加对父项 pom.xml 的引用,你尝试向子项添加 relativePath>.. /pom.xml/relativePath>
但仍然无效。
Maven-多模块项目
[
Docker文件
FROM alpine/git as clone
WORKDIR /app
RUN git clone https://github.com/RicardoVargasLeslie/manager.git
FROM openjdk:8-jdk-alpine as build
WORKDIR /workspace/app
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install -DskipTests
ENTRYPOINT ["java","-jar","/Web-0.0.1-SNAPSHOT.jar"]
儿童-pom.xml(网络)
<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.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>Web</artifactId>
<name>Web</name>
<description>Web Module</description>
父级-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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Core</name>
<description>Core Module</description>
<packaging>pom</packaging>
Docker 命令构建镜像
docker build -t rest-api .
命令行跟踪
$ docker build -t rest-api .
Sending build context to Docker daemon 42.92MB
Step 1/11 : FROM alpine/git as clone
---> a1d22e4b51ad
Step 2/11 : WORKDIR /app
---> Using cache
---> e53f5b4941b5
Step 3/11 : RUN git clone https://github.com/RicardoVargasLeslie/manager.git
---> Using cache
---> 490b2afea22c
Step 4/11 : FROM openjdk:8-jdk-alpine as build
---> a3562aa0b991
Step 5/11 : WORKDIR /workspace/app
---> Using cache
---> 0b7c106319e9
Step 6/11 : COPY mvnw .
---> Using cache
---> 2c7ab0b79d25
Step 7/11 : COPY .mvn .mvn
---> Using cache
---> eb9ec36b737a
Step 8/11 : COPY pom.xml .
---> Using cache
---> 2296a5fbd6ae
Step 9/11 : COPY src src
---> Using cache
---> 022a609f4376
Step 10/11 : RUN ./mvnw install -DskipTests
---> Running in 897cff2e3c3b
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 10
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.imricki.manager:Web:[unknown-version] (/workspace/app/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 10 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
The command '/bin/sh -c ./mvnw install -DskipTests' returned a non-zero code: 1
我不确定哪里出了问题或如何使构建工作,感谢您的帮助。
Maven 是一种工具,它支持以声明方式管理项目的依赖项。它通过标准化项目共享 jar 和 pom 文件(工件)的方式并使用 maven 坐标来声明项目依赖项(groupId、artifactId 和版本),然后在 public 的大型 maven 存储库中查找名为 Maven Central 的 jar 和 pom 文件。
为了将您的 jar/pom 文件(例如您的核心)作为 Maven 工件进行管理,您需要将您的工件部署到 Maven Central(public 任何人都可以访问的存储库) 或私人网络中某处的私人存储库(甚至在 Internet 上,并且可能需要身份验证)。在私有仓库的情况下,您需要包含您的私有仓库,这样您的 Maven 执行不仅会在 Maven Central 中查找工件,还会在您的私有仓库中查找工件。您可以通过将以下内容添加到 settings.xml
文件来实现此目的:
<!-- Authentication here -->
<servers>
<server>
<id>nexus</id>
<username>some_username</username>
<password>some_passowrd</password>
</server>
</servers>
...
<profiles>
<profile>
<id>nexus</id>
<!--Override the repository (and pluginRepository) "central" from the
Maven Super POM -->
<repositories>
<repository>
<id>nexus-release</id>
<name>nexus-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases</url>
</repository>
<repository>
<id>nexus-thirdparty</id>
<name>nexus-thirdparty</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin-release</id>
<name>nexus-plugin-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases/</url>
</pluginRepository>
<pluginRepository>
<id>nexus-plugin-third-party</id>
<name>nexus-plugin-third-party</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
...
我注意到您的 child pom.xml
文件引用了自定义 parent 模块。您需要确保您的 parent 模块位于 Maven 存储库 (Nexus/Artifactory) 中,并且您提供了一个 settings.xml
文件,其中包含 Docker 容器的存储库设置能够拉 parent pom.
我正在尝试从我的 Docker 文件构建一个 Docker 图像,但不断收到错误消息,例如无法找到父 pom.xml
来执行 maven 命令docker 文件并构建项目。
我环顾四周,你看到人们所做的是向子项 pom.xml
添加对父项 pom.xml 的引用,你尝试向子项添加 relativePath>.. /pom.xml/relativePath>
但仍然无效。
Maven-多模块项目
[
Docker文件
FROM alpine/git as clone
WORKDIR /app
RUN git clone https://github.com/RicardoVargasLeslie/manager.git
FROM openjdk:8-jdk-alpine as build
WORKDIR /workspace/app
COPY mvnw .
COPY .mvn .mvn
COPY pom.xml .
COPY src src
RUN ./mvnw install -DskipTests
ENTRYPOINT ["java","-jar","/Web-0.0.1-SNAPSHOT.jar"]
儿童-pom.xml(网络)
<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.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>Web</artifactId>
<name>Web</name>
<description>Web Module</description>
父级-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>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.imricki.manager</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Core</name>
<description>Core Module</description>
<packaging>pom</packaging>
Docker 命令构建镜像
docker build -t rest-api .
命令行跟踪
$ docker build -t rest-api .
Sending build context to Docker daemon 42.92MB
Step 1/11 : FROM alpine/git as clone
---> a1d22e4b51ad
Step 2/11 : WORKDIR /app
---> Using cache
---> e53f5b4941b5
Step 3/11 : RUN git clone https://github.com/RicardoVargasLeslie/manager.git
---> Using cache
---> 490b2afea22c
Step 4/11 : FROM openjdk:8-jdk-alpine as build
---> a3562aa0b991
Step 5/11 : WORKDIR /workspace/app
---> Using cache
---> 0b7c106319e9
Step 6/11 : COPY mvnw .
---> Using cache
---> 2c7ab0b79d25
Step 7/11 : COPY .mvn .mvn
---> Using cache
---> eb9ec36b737a
Step 8/11 : COPY pom.xml .
---> Using cache
---> 2296a5fbd6ae
Step 9/11 : COPY src src
---> Using cache
---> 022a609f4376
Step 10/11 : RUN ./mvnw install -DskipTests
---> Running in 897cff2e3c3b
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 10
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project com.imricki.manager:Web:[unknown-version] (/workspace/app/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.imricki.manager:Web:[unknown-version]: Could not find artifact com.imricki.manager:core:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 5, column 10 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
The command '/bin/sh -c ./mvnw install -DskipTests' returned a non-zero code: 1
我不确定哪里出了问题或如何使构建工作,感谢您的帮助。
Maven 是一种工具,它支持以声明方式管理项目的依赖项。它通过标准化项目共享 jar 和 pom 文件(工件)的方式并使用 maven 坐标来声明项目依赖项(groupId、artifactId 和版本),然后在 public 的大型 maven 存储库中查找名为 Maven Central 的 jar 和 pom 文件。
为了将您的 jar/pom 文件(例如您的核心)作为 Maven 工件进行管理,您需要将您的工件部署到 Maven Central(public 任何人都可以访问的存储库) 或私人网络中某处的私人存储库(甚至在 Internet 上,并且可能需要身份验证)。在私有仓库的情况下,您需要包含您的私有仓库,这样您的 Maven 执行不仅会在 Maven Central 中查找工件,还会在您的私有仓库中查找工件。您可以通过将以下内容添加到 settings.xml
文件来实现此目的:
<!-- Authentication here -->
<servers>
<server>
<id>nexus</id>
<username>some_username</username>
<password>some_passowrd</password>
</server>
</servers>
...
<profiles>
<profile>
<id>nexus</id>
<!--Override the repository (and pluginRepository) "central" from the
Maven Super POM -->
<repositories>
<repository>
<id>nexus-release</id>
<name>nexus-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases</url>
</repository>
<repository>
<id>nexus-thirdparty</id>
<name>nexus-thirdparty</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-plugin-release</id>
<name>nexus-plugin-release</name>
<url>http://hostname_or_ip_address/content/repositories/releases/</url>
</pluginRepository>
<pluginRepository>
<id>nexus-plugin-third-party</id>
<name>nexus-plugin-third-party</name>
<url>http://hostname_or_ip_address/content/repositories/thirdparty/</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
...
我注意到您的 child pom.xml
文件引用了自定义 parent 模块。您需要确保您的 parent 模块位于 Maven 存储库 (Nexus/Artifactory) 中,并且您提供了一个 settings.xml
文件,其中包含 Docker 容器的存储库设置能够拉 parent pom.