Could not find artifact com.sample:SampleSecurity:jar:0.0.1-SNAPSHOT when Docker build running

I cretaed Springboot based multi module project. right now i am trying to deploy this multi module project ousing docker.

but when i creting docker image for samplemanage then i getting this error.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  14.931 s
[INFO] Finished at: 2023-09-28T06:38:12Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project samplemange: Could not resolve dependencies for project com.sample:samplemange:jar:0.0.1-SNAPSHOT: Could not find artifact com.sample:SampleSecurity:jar:0.0.1-SNAPSHOT -> [Help 1]
[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/DependencyResolutionException
ERROR: Service 'web' failed to build: The command '/bin/sh -c mvn clean install -DskipTests' returned a non-zero code: 1

I created my custome artifact which name is sampleSecurity. whole project is maven and springboot based project. I need to add this artifact jar in sampleManage project when my docker build is runing. but i got this type of error. now stuck in this place to how add the my custom artifact jar in sampleManage docker build.

  • This my Folder structure which i maintain for this project.
Sample Project
 |
 |--> SampleManage(Api)
 |         |
 |         |-->src/
 |         |-->pom.xml
 |         |-->Dockerfile
 |         |-->docker-compose.xml
 | 
 |--> SampleSecurity(Module)
           |
           |-->src/
           |-->pom.xml
           |-->Dockerfile
  • SampleManage Dockerfile
FROM maven:3.8.4-openjdk-11-slim AS build
WORKDIR /app
COPY pom.xml .
RUN mvn clean install -DskipTests
COPY src .
RUN mvn package -DskipTests

FROM openjdk:11-jre-slim
WORKDIR /app
COPY --from=build /app/target/samplemange-0.0.1-SNAPSHOT.jar samplemange-0.0.1-SNAPSHOT.jar
CMD ["java", "-jar", "samplemange-0.0.1-SNAPSHOT.jar"]
  • SampleMange docker-compose.xml file
version: '3'
services:
  web:
    build: .
    ports:
      - 9090:9090
    depends_on:
      - sample-security
      - postgresdb
    volumes:
      - my-volume:/app
  sample-security:
    container_name: "sample-security"
    build:
      context: "/home/dev1010/jay/custom/sample-back-end/SampleSecurity"
      dockerfile: Dockerfile
    image: "sample-security-img:01"
    volumes:
      - my-volume:/app
  postgresdb:
    container_name: "postgresdb"
    image: "postgres:15"
    ports:
      - 5432:5432
    networks:
      - springboot-network
    environment:
      POSTGRES_DB: sampleMange
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: jaygohel
networks:
  springboot-network:
    driver: bridge
volumes:
  my-volume:
  • Sample Security Dokcerfile
FROM maven:3.8.4-openjdk-11-slim AS build
VOLUME /home/dev1010/app
WORKDIR /app
COPY pom.xml .
RUN mvn clean install -DskipTests
COPY src .
RUN mvn package -DskipTests

FROM openjdk:11-jre-slim
WORKDIR /app
COPY --from=build /app/target/ScurmmSecurity-0.0.1-SNAPSHOT.jar ScurmmSecurity-0.0.1-SNAPSHOT.jar

Please help me how can i handle this problem?

Leave a Comment