What is a classifier in SBT

时光毁灭记忆、已成空白 提交于 2019-12-01 03:23:47

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!