mavendependenciesmaven-3maven-dependencymaven-repository

Maven downloads all dependencies again because they were "cached from a remote repository ID that is unavailable in current build context"


I have a multi-staged Docker build.

In step one, I download and cache all dependencies (I use the Maven goal package for this). This is Docker layer is the base for all future build steps.

In step two, I build the project.

However, in step two, all dependencies get downloaded again. I made sure by using dive that the dependencies already exist in the Maven repository before and that the correct Maven repository is used.

When I run Maven in debugging mode by passing -X, I get this warning before each dependency is downloaded again:

Artifact XYZ is present in the local repository, but cached from a remote repository ID that is unavailable in current build context, verifying that is downloadable from XYZ

Here is the Maven source code where it is printed.

How can I solve this warning? How to keep Maven from downloading the dependencies again?


Solution

  • The problem was that I thought dependency:resolve also downloads all dependencies. But that's not what it does.