Languages
[Edit]
EN

Maven difference between package and install

5 points
Created by:
Root-ssh
7608

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:

  1. install - install the package into the local repository, for use as a dependency in other projects locally
  2. 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

References

Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.