Non-resolvable parent POM on Docker Build
Asked Answered
E

2

6

I’m trying to build a Docker image from my DockerFile but keep getting an error like it can't find the parent pom.xml to perform a maven command in the docker file and build the project. Ive been looking around and you see what people do is the add to the child pom.xml a reference to the parent pom.xml y tried adding a relativePath>.. /pom.xml/relativePath> to the child but still won't work.

Maven-multimodule project

[project structure[1]

DockerFile

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(Core)

<?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 comand to build image

docker build -t rest-api .

Comand-line Trace

$ 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

I’m not sure what wron or how to make the build work,thanks for any help.

Essam answered 5/8, 2019 at 21:22 Comment(4)
Out of interest though, why do you want your container to run the maven build? This can be run by the host and you just copy the .jar into your containerRupertruperta
to make it a bit more automatic and not have to be building on the hostEssam
Generally, a dedicated build server, like Jenkins is used for such tasks and the resulting artefacts are used to build a container but for local development, your way worksRupertruperta
I had the same problem and I solved it by doing a git clone from the docker container itself that brings the full repo including the parent, and then I used mvnw install -pl to install only the modules I need.Pargeting
R
1

Maven is a tool that enables a declarative way of managing your project's dependencies. It does that by standardising the way jar and pom files (artifacts) are shared by projects and uses maven coordinates to declare a project dependency (groupId, artifactId and version) which are then looked up in a large public maven repository of jar and pom files called Maven Central.

In order to have your jar/pom files (like your core for example) managed as a maven artifact, you need to deploy your artifact to either the Maven Central (public repository accessible by anyone) or a private repository some where in your private network (or even on the internet, and maybe with authentication). In the case of a private repository, you need to include the you private repository so that your maven execution not only looks for artifacts in Maven Central, but also in your private repository. You can achieve this by adding the following to your settings.xml file:

<!-- 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>
...

I noticed your child pom.xml file references a custom parent module. You need to make sure that your parent module is in a maven repository (Nexus/Artifactory) and that you supply a settings.xml file with the repository settings for the Docker container to be able to pull the parent pom.

Rupertruperta answered 5/8, 2019 at 21:46 Comment(13)
I understand what you mean, but if looking for another way if there is,projects hace dependencies with in them and y should be ok by building a web.jarEssam
I'm not sure I fully get your question here. Please edit your commentRupertruperta
I'm sorry I misunderstood you, the parent module is core witch is packaged as a pom, so I don't know how to approach this,you sugests y have to add a settings.xml?Essam
in my case y only want to dockerize the web module but im getting this error as i said so i will try out your solutionEssam
I'm aware of that and the solution is for you to dockerize you web module. The complexity is added by your requirement to run a maven build in your container, hence your container takes a dual role of assembling your application and being a runtime. Let me know how it goes thoughRupertruperta
yes, I'm trying to deploy the web module, but wen building with maven, I'm getting that it can't resolve dependencies from domain module, so I'm trying to build one single jar but still same error messageEssam
Have you deployed your parent pom to a maven repository?Rupertruperta
I'm having a look how to actually do this, I'm checking the maven deploy plugin this way could deploy all my target jars and then at build time to fetch them back? I'm looking at an example, or do you suggest a different approach?Essam
That’s correct. You can run your repository as a Docker container as well if you like. When you go the Docker route, you will have to make sure both your Docker containers or on the same network. Last I checked you could use the link flag when you run your web Docker containerRupertruperta
could i add my 2 Jars just before build on the docker file?Essam
Let us continue this discussion in chat.Essam
I dont understand very well. how we can dockerize a springboot application when we have parent pom.xml?Mullite
Put -1 because it doesn't address the root problem, correct solution should be to build the artifacts inside the docker instance. Not to do external work.Calaverite
M
5

In my case i was getting this due to the fact that apparently the Dockerfile instructions as copy can not see the parent folders !

meaning if you have a structure :

ParentProject
| 
--> Child Module A 
--> pom.xml
--> DockerFile
| 
--> Child Module B  
--> pom.xml
--> DockerFile
|
-> pom.xml

the Dockerfiles inside the modules can't perform actions like :

COPY ../pom.xml /

because it can't access localSystem ".." !! the solution was to move the Dockerfiles to the parent folder like this :

ParentProject
| 
--> Child Module A 
--> pom.xml
| 
--> Child Module B  
--> pom.xml
|
--> DockerFileA
--> DockerFileB
-> pom.xml

and then i was just doing something like this :

WORKDIR /app

COPY ./pom.xml /app

COPY ./ChildA/pom.xml /app/child-project/

It took me tons of times to figure this out, i needed to create a container just with COPY instructions without running maven , and then i drilled into the container files and found that the pom parent was not copied and actually somehow the docker copied the child pom as the parent pom for this instruction :

COPY ../pom.xml /

so you should know that when building docker , you can't copy files from parent folders in your localMachine since it does not have access to it. and it will execute the same command on the current folder, which makes it really hard to detect since no error is thrown upon it scenario.

Milanmilanese answered 4/7, 2023 at 7:32 Comment(0)
R
1

Maven is a tool that enables a declarative way of managing your project's dependencies. It does that by standardising the way jar and pom files (artifacts) are shared by projects and uses maven coordinates to declare a project dependency (groupId, artifactId and version) which are then looked up in a large public maven repository of jar and pom files called Maven Central.

In order to have your jar/pom files (like your core for example) managed as a maven artifact, you need to deploy your artifact to either the Maven Central (public repository accessible by anyone) or a private repository some where in your private network (or even on the internet, and maybe with authentication). In the case of a private repository, you need to include the you private repository so that your maven execution not only looks for artifacts in Maven Central, but also in your private repository. You can achieve this by adding the following to your settings.xml file:

<!-- 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>
...

I noticed your child pom.xml file references a custom parent module. You need to make sure that your parent module is in a maven repository (Nexus/Artifactory) and that you supply a settings.xml file with the repository settings for the Docker container to be able to pull the parent pom.

Rupertruperta answered 5/8, 2019 at 21:46 Comment(13)
I understand what you mean, but if looking for another way if there is,projects hace dependencies with in them and y should be ok by building a web.jarEssam
I'm not sure I fully get your question here. Please edit your commentRupertruperta
I'm sorry I misunderstood you, the parent module is core witch is packaged as a pom, so I don't know how to approach this,you sugests y have to add a settings.xml?Essam
in my case y only want to dockerize the web module but im getting this error as i said so i will try out your solutionEssam
I'm aware of that and the solution is for you to dockerize you web module. The complexity is added by your requirement to run a maven build in your container, hence your container takes a dual role of assembling your application and being a runtime. Let me know how it goes thoughRupertruperta
yes, I'm trying to deploy the web module, but wen building with maven, I'm getting that it can't resolve dependencies from domain module, so I'm trying to build one single jar but still same error messageEssam
Have you deployed your parent pom to a maven repository?Rupertruperta
I'm having a look how to actually do this, I'm checking the maven deploy plugin this way could deploy all my target jars and then at build time to fetch them back? I'm looking at an example, or do you suggest a different approach?Essam
That’s correct. You can run your repository as a Docker container as well if you like. When you go the Docker route, you will have to make sure both your Docker containers or on the same network. Last I checked you could use the link flag when you run your web Docker containerRupertruperta
could i add my 2 Jars just before build on the docker file?Essam
Let us continue this discussion in chat.Essam
I dont understand very well. how we can dockerize a springboot application when we have parent pom.xml?Mullite
Put -1 because it doesn't address the root problem, correct solution should be to build the artifacts inside the docker instance. Not to do external work.Calaverite

© 2022 - 2024 — McMap. All rights reserved.