14

What is meant under the term classifiers? Is it comes from Jars? For example in sbt-assembly plugin:

artifact in (Compile, assembly) ~= { art =>
  art.copy(`classifier` = Some("assembly"))
}
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319

2 Answers2

23

classifier is defined by Maven as the fifth element of a project coordinate, after groupId, artifactId, version and packaging.

More specifically (from the maven documentation, emphasis mine):

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

As a motivation for this element, consider for example a project that offers an artifact targeting JRE 1.5 but at the same time also an artifact that still supports JRE 1.4. The first artifact could be equipped with the classifier jdk15 and the second one with jdk14 such that clients can choose which one to use.

Another common use case for classifiers is the need to attach secondary artifacts to the project's main artifact. If you browse the Maven central repository, you will notice that the classifiers sources and javadoc are used to deploy the project source code and API docs along with the packaged class files.

For example, Maven central does not only contains the normal (without classifier) scala-library-2.10.2.jar, but also

  • scala-library-2.10.2-javadoc.jar, which by convention contains documentation (even if in this case it contains scaladoc and not javadoc),
  • scala-library-2.10.2-sources.jar which contains the sources.

Those two additional artifacts were published with a classifier.

SBT also allows you to add a classifier to a dependency. From the doc:

libraryDependencies += "org.testng" % "testng" % "5.7" classifier "jdk15"

In your case, it seems like the sbt-assembly plugin overrides all classifiers (only within the assembly task) to set them to assembly.

Community
  • 1
  • 1
gourlaysama
  • 11,240
  • 3
  • 44
  • 51
  • So this classifiers are some kind of a simple "marks" which i can use to distinguish my custom artifacts? –  Sep 02 '13 at 20:58
  • "In your case, it seems like the sbt-assembly plugin overrides all classifiers (only within the assembly task) to set them to assembly." I don't think it changes the context of `assembly` task. It's part of the instruction to publish fat jar by putting it into a different classifier. – Eugene Yokota Sep 02 '13 at 22:26
1

In addition to @gourlaysama's answer, see Publishing:

Published artifacts

By default, the main binary jar, a sources jar, and a API documentation jar are published. You can declare other types of artifacts to publish and disable or modify the default artifacts. See the Artifacts page for details.

and Artifacts:

Defining custom artifacts

In addition to configuring the built-in artifacts, you can declare other artifacts to publish. Multiple artifacts are allowed when using Ivy metadata, but a Maven POM file only supports distinguishing artifacts based on classifiers and these are not recorded in the POM.

Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319