Search code examples
scalasbtonejar

Renaming jar files with sbt when using SbtOneJar


When sbt builds a OneJar file using the SbtOneJar plugin it gives the built jar the name [name]_[scala-version]-[version]-one-jar.jar where name is the name of the project, scala-version is the scalaVersion and version is the version of the project, all variables in the build.sbt file.

How can one set up the build.sbt file so that the name of the jar is [name]-one-jar_[scala-version]-[version].jar


Solution

  • Add the following lines to the build.sbt:

    // This gets rid of the trailing "-one-jar"
    
    artifact in oneJar <<= moduleName(Artifact(_))
    
    // rename the jar
    
    artifact in oneJar ~= { (art: Artifact) =>
      art.copy(`type` = "jar", extension = "jar", name = art.name + "-one-jar")
    }