What is a classifier in SBT
Asked Answered
I

2

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"))
}
Into answered 2/9, 2013 at 10:56 Comment(0)
G
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.

Gavrielle answered 2/9, 2013 at 19:8 Comment(2)
So this classifiers are some kind of a simple "marks" which i can use to distinguish my custom artifacts?Into
"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.Multitude
M
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.

Multitude answered 2/9, 2013 at 22:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.