You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven中mvn install与mvn verify的区别及clean关键字的作用

Hey there! Let's break down the differences between mvn install and mvn verify, plus how the clean keyword alters their behavior—this is foundational stuff for smooth Maven workflows.

Core Differences: mvn verify vs mvn install

First, remember Maven follows a defined build lifecycle. Both commands run sequential phases, but they stop at different points with distinct goals:

mvn verify

  • This command executes all phases from validate up to verify in the default lifecycle. That means:
    • Validates project structure and dependencies
    • Compiles source code
    • Runs unit tests
    • Packages code into a jar/war/ear
    • Runs integration tests
    • Verifies the packaged artifact meets quality standards (like checking test coverage, code compliance, or custom validation rules)
  • The key takeaway: verify ensures your code and build output are valid and meet project requirements, but it doesn't save the artifact to your local Maven repository.

mvn install

  • This command goes a step further: it runs all phases up to install, which includes everything verify does. The extra step?
    • Installs the packaged artifact (jar/war/etc.) into your local Maven repository (usually located at ~/.m2/repository).
  • Why this matters: Once installed, other local projects can reference this artifact as a dependency in their pom.xml—super useful if you're working on multiple related projects.

To put it simply: verify is about "is this build good?"; install is about "this build is good, now let's make it available for other local projects to use."

How the clean Keyword Modifies These Commands

clean is a separate Maven lifecycle that operates independently of the default build lifecycle. When you prepend clean to either command, here's what happens:

  1. First, Maven runs the entire clean lifecycle: This deletes the target directory in your project root. The target folder stores all previous build outputs—compiled classes, packaged artifacts, test reports, etc.
  2. Then, it executes the subsequent build command (verify or install) from scratch.

Let's break down the modified commands:

  • mvn clean verify: Starts with a fresh slate by wiping old build artifacts, then runs the full validation-to-verification flow. This eliminates any stale files that might cause unexpected behavior (e.g., a leftover compiled class from a failed build overriding your new code).
  • mvn clean install:同样先清空target目录,再执行到install阶段。这保证了你安装到本地仓库的是完全基于最新代码的构件,不会出现"我改了代码但本地仓库还是旧版本"的尴尬情况。

Pro tip: If you ever run into weird build issues (like changes not showing up in the output), adding clean is often the first fix to try—it clears out any cached or outdated build files.

内容的提问来源于stack exchange,提问作者Nicholas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:43:09