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

查看:181
本文介绍了什么是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"))
}


推荐答案

分类器由Maven定义为项目坐标的第五个元素,在 groupId之后 artifactId 版本包装

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.

作为此元素的动机,请考虑例如a提供针对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还允许您向依赖项添加分类器。来自doc:

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

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

在您的情况下,似乎sbt-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天全站免登陆