英文:
in which maven life cycle, dependencies get downloaded from maven central repository to my local .m2 repository
问题
通常我按照以下Maven命令来构建和运行我的项目。
- mvn clean
- mvn clean verify
或者 - mvn clean install
- mvn spring-boot:run
我的疑惑是在哪个Maven生命周期阶段,依赖项会从Maven中央仓库下载到我的本地.m2仓库。
我查阅了下面提到的Maven生命周期,但没有找到在这些步骤中下载依赖项的地方。
- validate
- compile
- test
- package
- verify
- install
- deploy
请解释一下,这将非常有帮助。
英文:
Generally i follow below maven commands to build and run my project.
- mvn clean
- mvn clean verify
or - mvn clean install
- 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.
- validate
- compile
- test
- package
- verify
- install
- 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.
After running mvn compile
, the next lifecycle, a lot more dependencies are downloaded, including GSON:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论