Reputation: 8274
I'm trying to get maven to download all dependencies (compile, test, plugins, etc.) so that I can avoid having our dockerized builds waste unnecessary time downloading them over and over again.
We have dockerized our maven build so that we can run it from our jenkins without having a lot of build specific dependencies installed on the jenkins machine (Java, redis, maven dependencies, etc.). Our build relies on incremental docker builds that only executes steps that actually need re-running.
Our main build is a DockerFile that has several steps to install the jdk, maven, etc. Then it does a
COPY ./pom.xml /opt/inbot-api/pom.xml
RUN mvn dependency:copy-dependencies clean
This will download dependencies to the local maven repository and then cleans out the target directory.
Then we copy the source tree to the image and run the full build.
COPY ./src /opt/inbot-api/src
RUN mvn -e clean install
The general idea is that on a clean machine, docker will execute all the RUN steps but on incremental builds it will only rerun things that need re-running. After each run step, it stores an intermediary image. So, if the pom file doesn't change, there's no need to rerun the dependency fetching step because it would produce the exact same outcome. So, instead it loads the cached intermediary image with all the dependencies already downloaded. This is exactly what we want.
There's a lot more to our DockerFile that is not so relevant here but ultimately it produces a docker file with our compiled artifacts, an nginx config and all our runtime dependencies that we can deploy to ECS.
This nearly works except the mvn clean install
still downloads additional plugin dependencies on every build. So, these are dependencies that the copy-dependencies step does not cover.
My question, how do I get RUN mvn dependency:copy-dependencies clean
to download all dependencies including the plugin dependencies. I've seen people actually do a mvn verify clean
instead of mvn dependency:copy-dependencies clean
but that is kind of slow in our case. I was wondering if there was a better way to do this.
I'd appreciate any feedback on how to improve this.
Update
I now do a
RUN mvn -B -T 4 dependency:copy-dependencies dependency:resolve-plugins dependency:go-offline clean
And it still downloads more stuff with the mvn clean install
after that. A mvn -o clean install
still fails, despite the dependency:go-offline
. So, it seems this plugin is broken.
Upvotes: 15
Views: 9715
Reputation: 2245
The correct way to resolve plugins and dependencies explictly mentioned in your project is:
mvn dependency:go-offline
Documentation: https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#dependency-go-offline
Upvotes: 0
Reputation: 61
This works for me, no other dependencies to download:
RUN mvn -B dependency:resolve dependency:resolve-plugins
Upvotes: 4
Reputation: 321
I almost resolve with this:
RUN mvn install -DskipTests dependency:resolve dependency:resolve-plugins
Upvotes: -2
Reputation: 97359
For the plugin i would suggest to use mvn dependency:resolve-plugins
See the documentation: https://maven.apache.org/plugins/maven-dependency-plugin/
Upvotes: 1