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

huangapple go评论71阅读模式
英文:

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

问题

通常我按照以下Maven命令来构建和运行我的项目。

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

我的疑惑是在哪个Maven生命周期阶段,依赖项会从Maven中央仓库下载到我的本地.m2仓库。

我查阅了下面提到的Maven生命周期,但没有找到在这些步骤中下载依赖项的地方。

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

请解释一下,这将非常有帮助。

英文:

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.

答案1

得分: 1

当您创建一个Maven项目时,在验证之前会有一个名为“prepare-resources”的步骤,它会复制资源。而且,当您执行Maven清理操作时,它会下载依赖项。请阅读此链接以获取更多详细信息:

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

英文:

When you create a maven project, before validate there is step 'prepare-resources' which copies resources. Also when you do maven clean it will download dependencies. Read this link for more details

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

答案2

得分: 1

这里关于prepare-resources的另一个回答是不正确的。这可能会让Maven插件及其依赖项的下载变得混淆,但不会涉及项目的依赖关系。

实际上,在compile生命周期期间会下载这些依赖关系。

以下是一个示例项目,其中唯一的依赖项是GSON,我刚刚运行了process-resources生命周期(紧随其后compile生命周期)。在我的.m2/repository目录中,只有默认Maven插件所需的内容。请注意,没有com文件夹,这是GSON应该被下载到的位置。

在运行mvn compile之后,下一个生命周期会下载更多的依赖项,包括GSON:

英文:

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.

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

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

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

huangapple
  • 本文由 发表于 2020年8月9日 01:12:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63318165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定