How are “mvn clean package” and “mvn clean install” different?

后端 未结 5 970
-上瘾入骨i
-上瘾入骨i 2020-12-07 07:18

What exactly are the differences between mvn clean package and mvn clean install? When I run both of these commands, they both seem to do the same

5条回答
  •  生来不讨喜
    2020-12-07 07:23

    What clean does (common in both the commands) - removes all files generated by the previous build


    Coming to the difference between the commands package and install, you first need to understand the lifecycle of a maven project


    These are the default life cycle phases in maven

    • validate - validate the project is correct and all necessary information is available
    • compile - compile the source code of the project
    • test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
    • package - take the compiled code and package it in its distributable format, such as a JAR.
    • verify - run any checks on results of integration tests to ensure quality criteria are met
    • install - install the package into the local repository, for use as a dependency in other projects locally
    • deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

    How Maven works is, if you run a command for any of the lifecycle phases, it executes each default life cycle phase in order, before executing the command itself.

    order of execution

    validate >> compile >> test (optional) >> package >> verify >> install >> deploy

    So when you run the command mvn package, it runs the commands for all lifecycle phases till package

    validate >> compile >> test (optional) >> package

    And as for mvn install, it runs the commands for all lifecycle phases till install, which includes package as well

    validate >> compile >> test (optional) >> package >> verify >> install


    So, effectively what it means is, install commands does everything that package command does and some more (install the package into the local repository, for use as a dependency in other projects locally)

    Source: Maven lifecycle reference

提交回复
热议问题