Maven difference between package and install
Hi, today I would like to explain the difference between maven package and maven install.
1. 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:
C:\Users\seth\.m2\repository\com\dirask\0.0.1-SNAPSHOT\dirarsk-examples-0.0.1-SNAPSHOT.jar
2. 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