Maven的子模块无法在Docker构build的图像中find父pom / artifact

项目结构就像

parent-project -- pom.xml -- child-project-1 -- pom.xml -- Dockerfile -- child-project-2 -- pom.xml 

当mvntesting运行在本地child-project-1时,它工作正常。 但是,当mvntesting在child-project-1的Docker镜像中运行时,它找不到父pom。

我尝试使用Dockerfile中的ADD / COPY添加父pom.xml,但它抛出了构build上下文错误。 想知道如何从我们构buildDocker镜像的maven模块引用父pom

下面是日志, 正如前面提到的那样,child-project-1 pom.xml没有问题,并且在Docker之外构build的时候它正在build造

 + docker-compose -f ./child-project-1/src/test/resources/config/docker-compose.yml build test Building test Step 1/5 : FROM maven:3.5-jdk-8 ---> 080cf1fccf1c Step 2/5 : COPY . /usr/src/parent-project/child-project-1 ---> Using cache ---> af309a791cce Step 3/5 : WORKDIR /usr/src/parent-project/child-project-1 ---> Using cache ---> f9fa9a23570f Step 4/5 : RUN chmod +x /usr/src/parent-project/child-project-1/src/test/resources/config/run-tests.sh ---> Using cache ---> 3263333ba5a4 Step 5/5 : CMD /usr/src/parent-project/child-project-1/src/test/resources/config/run-tests.sh ---> Using cache ---> 32d391ba99a3 Successfully built 32d391ba99a3 Successfully tagged config_test:latest + docker-compose -f ./child-project-1/src/test/resources/config/docker-compose.yml up test Creating config_component_1 ... [36mtest_1 |[0m ------------ End Environment ------------ [36mtest_1 |[0m /usr/src/parent-project/child-project-1 [36mtest_1 |[0m [INFO] Scanning for projects... [36mtest_1 |[0m [ERROR] [ERROR] Some problems were encountered while processing the POMs: [36mtest_1 |[0m [FATAL] Non-resolvable parent POM for com.parent:child-project-1:[unknown-version]: Could not find artifact com.parent:cdx-components-test:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 9, column 10 [36mtest_1 |[0m @ [36mtest_1 |[0m [ERROR] The build could not read 1 project -> [Help 1] [36mtest_1 |[0m [ERROR] [36mtest_1 |[0m [ERROR] The project com.parent:child-project-1:[unknown-version] (/usr/src/parent-project/child-project-1/pom.xml) has 1 error [36mtest_1 |[0m [ERROR] Non-resolvable parent POM for com.parent:child-project-1:[unknown-version]: Could not find artifact com.parent:cdx-components-test:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 9, column 10 -> [Help 2] test_1 | [ERROR] The build could not read 1 project -> [Help 1] test_1 | [ERROR] test_1 | [ERROR] The project com.parent:child-project-1:[unknown-version] (/usr/src/parent-project/child-project-1/pom.xml) has 1 error test_1 | [ERROR] Non-resolvable parent POM for com.parent:child-project-1:[unknown-version]: Could not find artifact com.parent:cdx-components-test:pom:0.0.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 9, column 10 -> [Help 2]