什么是 SBT 中的分类器 [英] What is a classifier in SBT

查看:31
本文介绍了什么是 SBT 中的分类器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分类器一词是什么意思?它来自罐子吗?例如在 sbt-assembly 插件中:

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"))
}

推荐答案

classifier被Maven定义为项目坐标的第五个元素,在groupId之后,artifactIdversionpackaging.

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

更具体地说(来自 maven 文档,强调我的):

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

分类器允许区分由相同 POM 构建但内容不同的工件.它是一些可选且任意的字符串,如果存在的话,它会被附加到工件名称之后,紧跟在版本号之后.

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.

作为这个元素的动机,例如,考虑一个项目,它提供了一个针对 JRE 1.5 的工件,但同时也提供了一个仍然支持 JRE 1.4 的工件.第一个工件可以配备分类器 jdk15,第二个工件配备 jdk14,以便客户端可以选择使用哪一个.

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.

分类器的另一个常见用例是需要将次要工件附加到项目的主要工件.如果您浏览 Maven 中央存储库,您会注意到分类器源和 javadoc 用于部署项目源代码和 API 文档以及打包的类文件.

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.

例如,Maven central 不仅包含普通的(不带分类器)scala-library-2.10.2.jar,还包含

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,按照惯例包含文档(即使在这种情况下它包含 scaladoc 而不是 javadoc),
  • scala-library-2.10.2-sources.jar,其中包含源代码.
  • 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 还允许您将分类器添加到依赖项.来自文档:

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

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

在您的情况下,sbt-assembly 插件似乎覆盖了所有分类器(仅在组装任务中)以将它们设置为 assembly.

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

这篇关于什么是 SBT 中的分类器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆