为什么 'mvn install' war 个项目?

Why 'mvn install' war projects?

我的 maven 项目打包了一个 war,它只被部署并且本身不依赖于其他项目(换句话说是最终可部署的)。

问题

对于最终的可部署工件,确实可能没有理由调用 install 阶段而不是 package 阶段:您想要构建 .war 文件,但您没有确实不需要将它安装在您的本地存储库中。

但是,您可能希望始终运行 集成测试成为一种习惯,如果有的话。查看 default Maven lifecycle 这些阶段发生在 之后 包装:

package take the compiled code and package it in its distributable format, such as a JAR.
pre-integration-test perform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-test process and deploy the package if necessary into an environment where integration tests can be run.
post-integration-test perform actions required after integration tests have been executed. This may including cleaning up the environment.
verify run any checks to verify the package is valid and meets quality criteria.
install install the package into the local repository, for use as a dependency in other projects locally.

因此,通过调用 install,您将确保始终执行集成测试。实际上,更短的调用是

mvn clean verify

不太流行但在这些情况下更有效。