Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fetch all maven dependencies including plugin dependencies

Tags:

java

docker

maven

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.

like image 383
Jilles van Gurp Avatar asked Dec 10 '15 13:12

Jilles van Gurp


People also ask

How can I download all the dependency files?

If you want do download them all, you can try using mvn dependency:copy-dependencies . Then, you'll find all project dependencies in target/dependencies directory of your project. This also includes transitive dependencies. To add them all as eclipse dependencies, you may want to try maven-eclipse-plugin .

Does Maven download dependencies of dependencies?

Maven uses HTTP to download its dependencies along with the dependencies of the Maven project (such as Camel). If you run Maven and it fails to download your required dependencies it's likely to be caused by your local firewall & HTTP proxy configurations.

What is the difference between plugins and dependencies in Maven?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.


1 Answers

This works for me, no other dependencies to download:

RUN mvn -B dependency:resolve dependency:resolve-plugins
like image 74
Pavel Sklenar Avatar answered Sep 19 '22 21:09

Pavel Sklenar