Docker and Maven dependency offline Docker and Maven dependency offline docker docker

Docker and Maven dependency offline


The problem here is that when maven performs dependency:go-offline it looks for all dependencies including dependencies on the other modules in the project. But at the moment of running there are no built artifacts for the module-dependencies, because they have never been built. Read more here.

It is a known issue, at the same time, there is no solution except building the dependent modules first.

But in your particular case it is not possible (once you build the dependencies the command can't be cached by Docker).

A workaround: The dependency plugin has an option called excludeArtifactIds using which you can exclude some of the modules that do require modular dependencies. Having this, you will be able to resolve all dependencies except of those in the excluded modules.

mvn dependency:go-offline -DexcludeArtifactIds:wc-dao,some-other-artifact

The same way you can use excludeGroupIds if you want to exclude a group.

Of course, this way Docker won't cache all you wanted, but better to have something cached than nothing.


Okay,

so to solve this problem, i used docker volumes:

docker run --rm -v <my-java-app>:/app -v <a folder to maven repository>:/root/.m2 -w /app maven:3.6-jdk-8 mvn clean install -T 2C -DskipTests=true

This is the best solution we will get presently.