You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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 assemblyOutputPath setting overrides sbt-assembly's default output location (which was target/scala-2.12/my-project-assembly-0.1.jar for you).
  • When you run sbt assembly, the jar will be directly written to dist/my-project.jar—no manual renaming or moving required.
  • If the dist directory 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:03:03