本地回购的“ mvn 部署”和“ mvn 安装”有什么区别?

我的团队使用一个内部团队 maven repo,它是从使用 Apache 的开发服务器共享的。我们还在同一台机器上运行 ContinuumCI 服务器。Continium 中的 Maven 构建是以“安装”为目标运行的,这个目标是将最终的工件直接复制到共享目录中。

问题是,使用 mvn install向共享回购添加文件和使用部署目标(mvn- 部署插件)有什么区别?

在我看来,使用 mvn deploy会带来额外的配置麻烦,但是我在某处读到过,由于与 maven 的内部工作有关的某些原因,将文件安装到共享回购中是一个糟糕的主意。

Update: 我了解了 deployinstall之间的功能差异; 我实际上更感兴趣的是在 maven repo 中创建哪些文件的底层细节。

126438 次浏览

From the Maven docs, sounds like it's just a difference in which repository you install the package into:

  • install - install the package into the local repository, for use as a dependency in other projects locally
  • deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Maybe there is some confusion in that "install" to the CI server installs it to it's local repository, which then you as a user are sharing?

"matt b" has it right, but to be specific, the "install" goal copies your built target to the local repository on your file system; useful for small changes across projects not currently meant for the full group.

The "deploy" goal uploads it to your shared repository for when your work is finished, and then can be shared by other people who require it for their project.

In your case, it seems that "install" is used to make the management of the deployment easier since CI's local repo is the shared repo. If CI was on another box, it would have to use the "deploy" goal.

Ken, good question. I should be more explicit in the The Definitive Guide about the difference. "install" and "deploy" serve two different purposes in a build. "install" refers to the process of installing an artifact in your local repository. "deploy" refers to the process of deploying an artifact to a remote repository.

Example:

  1. When I run a large multi-module project on a my machine, I'm going to usually run "mvn install". This is going to install all of the generated binary software artifacts (usually JARs) in my local repository. Then when I build individual modules in the build, Maven is going to retrieve the dependencies from the local repository.

  2. When it comes time to deploy snapshots or releases, I'm going to run "mvn deploy". Running this is going to attempt to deploy the files to a remote repository or server. Usually I'm going to be deploying to a repository manager such as Nexus

It is true that running "deploy" is going to require some extra configuration, you are going to have to supply a distributionManagement section in your POM.