Docker – multi stage build with multi-module Maven project

I have a Maven Project that has a root pom.xml file that has multiple sub-folders as modules and dependencies.

It looks something like this:


Each module/dependency generates its own JAR file.

I’m using the Maven Dependency Plugin to unpack my final JAR to classes and dependencies folders separately.

So my Dockerfile has something like this in it:

COPY ${FOLDER}/BOOT-INF/lib /app/lib
COPY ${FOLDER}/BOOT-INF/classes /app

The dependencies are in /app/lib, but since my sub-folders (modules) are some of those dependencies, that COPY layer never gets cached since those sub-folders are where i change my code.
(In that /app/lib folder there’s a mix of modules dependencies and 3rd party dependencies).

Is there any way i can cache all other dependencies (3rd party) other than those modules?
Or is it not possible since in the end they’re all dependencies?

Source: StackOverflow