Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvn install vs jar:jar

What is the difference between the "mvn install" command, versus the use of the jar:jar plugin ?

Its clear that "install" seems to build a jar, and so, I am wondering what the need for the jar:jar plugin would be.

like image 926
jayunit100 Avatar asked Nov 30 '22 01:11

jayunit100


1 Answers

There are two types of things you can specify on the maven command line:

  • lifecycle phases (these do not include a : character)

  • plugin goals (these include at least one : character, depending on how fully you specify the plugin, it could be short-name:goal or groupId:artifactId:goal or groupId:artifactId:version:goal)

There are three lifecycles: default, clean and site. Each lifecycle consists of a series of phases. When you specify a phase in a lifecycle then Maven will execute in order all the phases in that lifecycle up to and including the specified phase.

When you specify a plugin goal then that plugin goal is invoked and only that plugin goal.

Maven has a concept of a packaging which defines a default set of plugin bindings to lifecycle phases. For example the jar packaging (which is default unless your pom.xml includes a <packaging>...</packaging> element) by default binds jar:jar to the package phase and binds install:install to the install phase.

So when you type

$ mvn package

Maven will run all the way through the lifecycle phases executing plugins that are bound (either from the lifecycle or by specifying plugin executions in the pom) as it goes along.

When you type

$ mvn jar:jar

Maven will just run the jar plugin's jar goal.

The lifecycle is 99 times out of 100 the one you want to use.

Here are the times you would typically want to invoke plugin goals directly

  • jetty:run to start a webapp server

  • surefire:test to quickly re-run the tests (usually with -Dtest=... to specify the specific one

  • release:prepare release:perform to release your code

  • versions:... to do some updating or querying of version related stuff, e.g. versions:display-plugin-updates

  • ship:ship or cargo:deployer-deploy to push (ship) your built artifacts to a hosting environment

like image 67
Stephen Connolly Avatar answered Dec 20 '22 22:12

Stephen Connolly