in which maven life cycle, dependencies get downloaded from maven central repository to my local .m2 repository

Viewed 334

Generally i follow below maven commands to build and run my project.

  1. mvn clean
  2. mvn clean verify or
  3. mvn clean install
  4. mvn spring-boot:run

My doubt is in which maven life cycle, dependencies get downloaded from maven central repository to my local .m2 repository.

I went through below mentioned maven life cycle but no where i found that in this steps dependency gets downloaded.

  1. validate
  2. compile
  3. test
  4. package
  5. verify
  6. install
  7. deploy

Please explain it would be really helpful.

2 Answers

The other answer here of prepare-resources is incorrect. That may be confusing the downloading of Maven plugins and their dependencies, but not the project's dependencies.

They actually are downloaded during the compile lifecycle.

Here is an example of a project where the only dependency is GSON, and I just finished running the process-resources lifecycle, the one that immediately precedes compile lifecycle. The only things present in my .m2/repository directory are things required by the default Maven plugins. Note that there is no com folder, which is where GSON would have been downloaded to.

A few folders in .m2/repository, but no com folder

After running mvn compile, the next lifecycle, a lot more dependencies are downloaded, including GSON:

A com folder is now present

Related