Hi, today I would like to explain the difference between maven package and maven install.
mvn install - will build our jar + put it into target dir and copy it to maven .m2 repository on our PC, example of maven local repository path:
mvn package - will build our jar + put it into target dir, nothing more and nothing less
From maven documentation:
- install - install the package into the local repository, for use as a dependency in other projects locally
- package - take the compiled code and package it in its distributable format, such as a JAR.
Maven clean - why to run it in the first place?
mvn clean - will remove our target directory
It is good practice to run maven clean command before running mvn install or mvn package command. Maven clean will remove our target directory and in that way we will ensure our code and resources are freshly compiled to target directory.
Personally I like to use 2 maven commands to build my project.
First, just simple clean install:
$ mvn clean install
Second, clean install with skipping unit tests to save my time if something went wrong during development and I really need this jar fast for dev testing:
$ mvn clean install -Dmaven.test.skip=true