简体   繁体   English

在 maven 生命周期中,依赖项从 maven 中央存储库下载到我的 local.m2 存储库

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

Generally i follow below maven commands to build and run my project.通常我按照下面的 maven 命令来构建和运行我的项目。

  1. mvn clean mvn 清洁
  2. mvn clean verify or mvn clean verify 或
  3. mvn clean install mvn 干净安装
  4. mvn spring-boot:run mvn spring-boot:运行

My doubt is in which maven life cycle, dependencies get downloaded from maven central repository to my local.m2 repository.我的疑问是在哪个 maven 生命周期中,依赖项从 maven 中央存储库下载到我的 local.m2 存储库。

I went through below mentioned maven life cycle but no where i found that in this steps dependency gets downloaded .我经历了下面提到的 maven 生命周期,但我没有发现在此步骤中下载了依赖项。

  1. validate证实
  2. compile编译
  3. test测试
  4. package package
  5. verify核实
  6. install安装
  7. deploy部署

Please explain it would be really helpful.请解释这将非常有帮助。

When you create a maven project, before validate there is step 'prepare-resources' which copies resources.当您创建 maven 项目时,在验证之前有一个复制资源的步骤“准备资源”。 Also when you do maven clean it will download dependencies.此外,当您执行 maven clean 时,它将下载依赖项。 Read this link for more details阅读此链接了解更多详情

https://www.tutorialspoint.com/maven/maven_build_life_cycle.htm https://www.tutorialspoint.com/maven/maven_build_life_cycle.htm

The other answer here of prepare-resources is incorrect. prepare-resources的另一个答案是不正确的。 That may be confusing the downloading of Maven plugins and their dependencies, but not the project's dependencies.这可能会混淆 Maven 插件及其依赖项的下载,但不会混淆项目的依赖项。

They actually are downloaded during the compile lifecycle.它们实际上是在compile生命周期中下载的。

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.这是一个项目示例,其中唯一的依赖项是 GSON,我刚刚完成了process-resources生命周期的运行,它紧接在compile生命周期之前。 The only things present in my .m2/repository directory are things required by the default Maven plugins.我的.m2/repository目录中唯一存在的东西是默认 Maven 插件所需的东西。 Note that there is no com folder, which is where GSON would have been downloaded to.请注意,没有com文件夹,这是 GSON 将被下载到的位置。

.m2/repository 中有几个文件夹,但没有 com 文件夹

After running mvn compile , the next lifecycle, a lot more dependencies are downloaded, including GSON:运行mvn compile后,下一个生命周期,下载了更多的依赖项,包括 GSON:

现在存在一个 com 文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM