本文介紹了Docker內部版本上的不可解析父POM的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試從我的DockerFile構建Docker鏡像,但不斷收到錯誤消息,如找不到父pom.xml
在docker文件中執行maven命令并構建項目。
我四處看了看,您看到人們所做的是將pom.xml
添加到子項pom.xml
引用父pom.xml y嘗試向子項添加relativePath>.. /pom.xml/relativePath>
,但仍然不起作用。
Maven-多模塊項目
[
文檔文件
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"]
Child-pom.xml(Web)
<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>
Parent-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和版本),然后在名為Maven Central的JAR和POM文件的大型公共Maven存儲庫中進行查找。
為了將您的JAR/POM文件(例如您的核心)作為maven構件進行管理,您需要將您的構件部署到Maven Central(任何人都可以訪問的公共存儲庫)或私有存儲庫中的某個位置(或者甚至在Internet上,并且可能使用身份驗證)。對于私有存儲庫,您需要包括You私有存儲庫,這樣您的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>
...
我注意到您的子pom.xml
文件引用了一個自定義父模塊。您需要確保您的父模塊位于maven存儲庫(Nexus/ArtiFactory)中,并且您提供了一個settings.xml
文件,其中包含Docker容器能夠提取父POM的存儲庫設置。
這篇關于Docker內部版本上的不可解析父POM的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,