5

I have a config like this for the project in my build.sbt:

name := "test-utils_0.1"
organization := "com.my.test.project"
version := "0.6.0-SNAPSHOT"

My problem is - when I run sbt clean publish-local command, the jar gets published in the .ivy2 local directory as:

test-utils_0-1_2.11

What is the best way to change it to test-utils_0.1_2.11?

UPDATE I have also tried to modify the artifactName property of build.sbt in this way:

name := "test-utils"
organization := "com.my.test.project"
version := "0.6.0-SNAPSHOT"
utilsVersion := "0.1"

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

And I get the jar called test-utils_0.1_2.11.jar, but this does NOT change the publish name in my repo (it is still being published using the name property, ie. test-utils_2.11/0.6.0-SNAPSHOT/test-utils_2.11.jar)

TheMP
  • 8,257
  • 9
  • 44
  • 73

2 Answers2

0

Replace . with _ in artifact.name with artifact.name.replace(".", "_"):

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

In case you want to customize another parts of your path, use something like this:

  def customStyleBasePattern = "[organisation]/[module](_[scalaVersion])(_[sbtVersion])/[revision]/[artifact]-[revision](-[classifier]).[ext]"
  val ivyLocal = Resolver.file("local", file(Path.userHome.absolutePath + "/.ivy2/local2"))(Patterns(Nil, customStyleBasePattern :: Nil, true))

  externalResolvers += ivyLocal
Nikita
  • 4,435
  • 3
  • 24
  • 44
  • Doesn't seem to work - creates .jar with characters replaced but publishes to ivy it with the old, not replaced name. According to the doc `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 want to know if there is any way to influence the name that is actually published. – TheMP Jul 27 '16 at 07:18
0

You need to change the artifact name (SBT 1.2.8):

lazy val utilsVersion = "0.1"

artifact in (Compile, packageBin) := {
  val old = artifact.in(Compile, packageBin).value
  old.withName(old.name + "_" + utilsVersion)
}

It will produce what you need:

[info]  published test-utils_0.1_2.12 to /home/pkhamutou/.ivy2/local/com.my.test.project/test-utils_2.12/0.6.0-SNAPSHOT/jars/test-utils_0.1_2.12.jar

You can repeat the same for packageDoc and packageSrc.

Pavel Khamutou
  • 111
  • 2
  • 4