If the version of a project foo is 1.0-SNAPSHOT, should running the command
mvn install -Dclassifier=bar
install foo-1.0-SNAPSHOT-bar.jar in my local .m2 directory? I tried doing this but it installs foo-1.0-SNAPSHOT.jar and maven install plugin doesn’t give too much detail about the -Dclassifier option.
Is there a way to install (locally) a jar with a classifier?
That
-Dclassifierparameter is associated with theinstall:install-filegoal, which is not the goal executed by the install phase of the default build lifecycle. Rather, it is used to install secondary artifacts in an ad hoc command line fashion. In other words, it’s for sticking stuff in the repository outside the context of a normal running maven build.When you invoke the default build lifecycle with
mvn install, he install phase executes the[install:install][1]goal. So, when you executedmvn install -Dclassifier=bar, you executed the default built lifecycle, and that parameter was not used for anything.The
install:installgoal, as it states in the docs, installs theprimary artifactas well as ansecondary, akaattached, artifacts. The jar produced by your build is the primary artifact. It does NOT have a classifier. All of the attached artifacts require a fourth maven coordinate to uniquely identify them from the primary artifact. This coordinate is the classifier.You have no need for a classifier unless you have attached artifacts. Where do attached artifacts come from? They are things that your build produces in addition to the primary artifact. So, it could be something built by the assembly plugin. It could be another jar containing the source files of your project, etc. The classifier is determined by the mechanism that attaches the secondary artifact, e.g. the assembly plugin.