When exactly does maven download dependencies?

Viewed 837

I have been using maven for years now but have just realised the need to understand the actual time (maven phase) when the dependencies would be downloaded. I have read maven docs but could not find the actual phase at which the dependencies would get downloaded.

Below is the simplified explanation of my use case:

I have a Jenkins Build job which has 2 stages (since, my code is dependent on snapshots of other internal projects, I am using -U to update the snapshots as I want to build my code with the latest snapshots of other projects):

1. Fast check (check if all the code compiles)

 mvn test-compile -U

3. Slow check (build and unit test the whole code)

mvn verify -U scoverage:report-only

Now, while step 1 was getting executed, if someone updates the snapshot of a dependency, I would be running my test-compile and verify goals on different snapshots.

I would like to avoid that and am wondering if I remove -U from the step 2, would all the dependencies still be updated when step 1 was run? Or, could there be a case where step 1 only downloaded the dependencies that were relevant to it to run the test-compile phase while verify phase needed a super-set of dependencies?

2 Answers

The goal dependency:resolve binds by default to the lifecycle phase generate-sources, the third phase after validate and initialize. Then they are all available locally.

Agree, removing the -U in the 2nd step is probably right thing to do as long as acting on the same pom.

This also assumes the local repo is specific (private) to the job. By default, the maven.local repo is common to the user, in the ${user.home}/.m2. Multiple executors on the same node will share the default repo.

AFAIK it is save to remove -U from the second step.

Dependencies are all resolved at the very beginning of each build.

Related