Reputation: 175
I have monorepo with some apps and pom.xml
. I want to be able to build just specified modules in Dockerfile.
Project structure is:
pom.xml
- app-core (this is runnable app)
- pom.xml
- app-common (this is just common classes)
- pom.xml
- app-crawler (this is second runnable app)
- pom.xml
Main pom.xml
has all apps as modules.
app-core
and app-crawler
have dependencies of app-common
.
Now I have such Dockerfile for app-crawler
:
FROM maven:3.8.5-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
COPY app-core/pom.xml app-core/pom.xml
COPY app-common/pom.xml app-common/pom.xml
COPY app-crawler/pom.xml app-crawler/pom.xml
RUN mvn --no-transfer-progress dependency:go-offline
COPY app-core/src app-core/src
COPY app-common/src app-common/src
COPY app-crawler/src app-crawler/src
RUN mvn package -DskipTests
FROM openjdk:17-jdk-slim
WORKDIR /
COPY --from=build /app/app-crawler/target/*.jar application.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "application.jar"]
If I do not copy all modules and build whole project, I see exception that some modules are not found.
Child module /app/app-core of /app/pom.xml does not exist
But this Dockerfile does not look good, because in case of new module added, I need to update all Dockerfiles.
My question is how to build only app-common
and app-crawler
modules without copying all other.
I tried to avoid copying whole project by using flags:
FROM maven:3.8.5-openjdk-17 AS build
WORKDIR /app
COPY pom.xml .
COPY app-common/pom.xml app-common/pom.xml
COPY app-crawler/pom.xml app-crawler/pom.xml
RUN mvn --no-transfer-progress dependency:go-offline -am app-common app-crawler
COPY app-common/src app-common/src
COPY app-crawler/src app-crawler/src
RUN mvn package -DskipTests -am app-common,app-crawler
FROM openjdk:17-jdk-slim
WORKDIR /
COPY --from=build /app/app-crawler/target/*.jar application.jar
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "application.jar"]
This still shows exception of not found module app-core
Upvotes: 0
Views: 32