67

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?

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).

James
  • 3,312
  • 1
  • 21
  • 15

4 Answers4

90

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.

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

// disable using the Scala version in output paths and artifacts
crossPaths := false
Neil
  • 7,482
  • 6
  • 50
  • 56
James
  • 3,312
  • 1
  • 21
  • 15
18

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.

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

Community
  • 1
  • 1
Francis Toth
  • 1,595
  • 1
  • 11
  • 23
  • 2
    This solution is better than the accepted one, as you have only to change the dependency where the Scala version number is a problem. By setting 'crosspaths' to false you have to change all dependencies and manually add the Scala version. – Victor Jan 10 '18 at 06:28
11

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

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
}
expert
  • 29,290
  • 30
  • 110
  • 214
Paul Butcher
  • 10,722
  • 3
  • 40
  • 44
  • 1
    Thanks Paul. Unfortunately that doesn't have any observable effect on the published artifact name. The published artifact still has the Scala version on the end of the name. I added junk to the resulting string and that did not show up either. Here's my build.scala: http://pastie.org/2931253 – James Nov 28 '11 at 03:06
  • 1
    Also, that page you referenced says that the artifactName setting will NOT affect the published name. "The function may be modified to produce different local names for artifacts without affecting the published name, which is determined by the artifact definition combined with the repository pattern.". I did try modifying the artifact setting and providing a new Artifact but that doesn't let me directly get rid of the scala version postfix. It LOOKS like sbt is going to pass scalaVersion to the artifactName method of Artifact. Is overriding that method my only option? – James Nov 28 '11 at 03:09
  • Ah damn - sorry, it's not something I've tried before and that page looked like it was exactly what you needed at first glance. Looks like you've found it anyway - sorry for the curve ball. – Paul Butcher Nov 28 '11 at 09:24
  • No problem. It pointed me in the right direction if nothing else. – James Nov 29 '11 at 20:55
6

While the accepted answer is strictly correct, you should never set crossVersions to false on 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.

Only set crossVersions to false for projects, like those in the question, that are strictly Java only.

gregsymons
  • 317
  • 2
  • 11
  • Is it possible to publish two artifacts? One with the scala version and one without? – Rohan Prabhu May 12 '15 at 14:23
  • I suppose you could, but I'm not sure I understand why you would? What would you do if you actually cross-compiled your scala for multiple compiler versions? – gregsymons May 19 '15 at 19:48