Maven子模块无法在使用Docker构建的映像中找到父pom / artifact

时间:2017-10-12 22:00:02

标签: java maven docker docker-compose dockerfile

项目结构就像

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

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

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

下面是日志,如前所述,child-project-1 pom.xml没有问题,并且在Docker外部构建时构建正常

+ 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]

0 个答案:

没有答案