如何从使用 simple-build-tool 构建+发布的工件中删除 _<scala-version> 后缀?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8288859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 03:42:37  来源:igfitidea点击:

How do you remove the _<scala-version> postfix from artifacts built+published with simple-build-tool?

scalasbt

提问by James

I'm building a few Java-only projects using simple-build-tool. When I publish the artifacts from the projects using, say, sbt publish-local then the resulting artifacts have the Scala version appended to their name. With a Scala project this would make sense, but since these are Java only projects it doesn't. How would I disable this postfixing of the Scala version? Or can I?

我正在使用 simple-build-tool 构建一些仅限 Java 的项目。当我使用 sbt publish-local 从项目中发布工件时,生成的工件会将 Scala 版本附加到它们的名称中。对于 Scala 项目,这是有道理的,但由于这些只是 Java 项目,因此没有意义。我将如何禁用 Scala 版本的这个后缀?或者我可以吗?

For reference I'm using sbt 0.11.1, Scala 2.9.1 and a .sbt file for build configuration (though moving to a full project config would be no problem).

作为参考,我使用 sbt 0.11.1、Scala 2.9.1 和 .sbt 文件进行构建配置(尽管迁移到完整的项目配置没有问题)。

回答by James

After looking around how Artifact.artifactName is implemented and ultimately used it seems that the way to turn this off is to specify false for the crossPath setting. This is documented in one of the quick configuration examples on the xsbt wiki.

在查看 Artifact.artifactName 是如何实现并最终使用之后,似乎关闭它的方法是为 crossPath 设置指定 false 。这在 xsbt wiki 上的快速配置示例之一中有所记录。

http://www.scala-sbt.org/release/docs/Examples/Quick-Configuration-Examples

http://www.scala-sbt.org/release/docs/Examples/Quick-Configuration-Examples

// disable using the Scala version in output paths and artifacts
crossPaths := false

回答by Francis Toth

I know this question is old, but I've been asking myself the same question, and there's actually a very simple way to do this now. All you have to do is to declare the dependency using %instead of %%:

我知道这个问题很老,但我一直在问自己同样的问题,现在实际上有一种非常简单的方法可以做到这一点。您所要做的就是使用%而不是声明依赖项%%

%: A method used to construct an Ivy Module ID from the strings you supply.

%%: When used after the groupID, it automatically adds your project's Scala version (such as _2.10) to the end of the artifact name.

%:一种用于根据您提供的字符串构造 Ivy 模块 ID 的方法。

%%:在 groupID 之后使用时,它会自动将您项目的 Scala 版本(例如 _2.10)添加到工件名称的末尾。

http://alvinalexander.com/scala/sbt-how-to-manage-project-dependencies-in-scala

http://alvinalexander.com/scala/sbt-how-to-manage-project-dependencies-in-scala

回答by Paul Butcher

This is documented on the xsbt wiki under Modifying default artifacts. From that page:

这在 xsbt wiki 的Modifying default artifacts下进行了记录。从该页面:

For example, to produce a minimal name without a classifier or cross path:

artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
  artifact.name + "-" + module.revision + "." + artifact.extension
}

例如,要生成没有分类器或交叉路径的最小名称:

artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
  artifact.name + "-" + module.revision + "." + artifact.extension
}

回答by gregsymons

While the accepted answer is strictly correct, you should neverset crossVersionsto falseon publicly published Scala artifacts. The embedded scala version is an important compatibility feature, since different versions of the Scala libraries may not be binary compatible.

虽然接受的答案是完全正确,你应该永远不会设置crossVersionsfalse上公开发布斯卡拉文物。嵌入式 Scala 版本是一个重要的兼容性特性,因为不同版本的 Scala 库可能不兼容二进制。

Only set crossVersionsto falsefor projects, like those in the question, that are strictly Java only.

只设置crossVersionsfalse了项目,就像那些有问题,只有严格的Java。