如何在SBT中重命名并迁移Assembly插件生成的UberJar?
Solution for Auto-Renaming & Relocating sbt-assembly UberJar (0.14.6)
Hey there, since you're already using sbt-assembly 0.14.6 with your existing merge strategy, you don't need any external scripts to rename and move the generated uber jar—you can handle this directly in your build.sbt by setting the assemblyOutputPath key.
Here's how to update your configuration:
// Keep your existing merge strategy assemblyMergeStrategy in assembly := { case PathList("META-INF", xs @ _*) => MergeStrategy.discard case x => MergeStrategy.first } // Define your desired output path and consistent filename assemblyOutputPath in assembly := file("dist/my-project.jar")
What this does:
- The
assemblyOutputPathsetting overrides sbt-assembly's default output location (which wastarget/scala-2.12/my-project-assembly-0.1.jarfor you). - When you run
sbt assembly, the jar will be directly written todist/my-project.jar—no manual renaming or moving required. - If the
distdirectory doesn't exist, sbt will automatically create it during the assembly process.
If you want to keep the version in the filename but still control the directory, you can use sbt's built-in version value dynamically:
assemblyOutputPath in assembly := file(s"dist/my-project-${version.value}.jar")
This approach is fully integrated with sbt-assembly 0.14.6, so it's maintainable and doesn't rely on external tools or scripts.
内容的提问来源于stack exchange,提问作者xmar
相关产品推荐
相关产品推荐

