12

I have multi-project Build.scala. Is there a way to place all jars generated by sbt-assembly in the root target directory?

For example, consider the following:

lazy val root = Project("root", file(".")).aggregate(hello)

lazy val hello = Project(id = "hello", base = file("hello"))
   .settings(assemblySettings: _*)

As is, if I run sbt assembly, hello.jar would be placed in hello/target/<scala-version>/. Is possible instead to place it in /target/<scala-version>/?

I know it's possible to specify the outputPath I want by adding the following setting:

target in assembly := file("target/scala-2.11/")

Is there any way to make this more generic? For example, so it is not necessary to manually specify the scala version?

user2597851
  • 121
  • 1
  • 4

3 Answers3

10
assemblyOutputPath in assembly := file("yourpath")
randomsearch
  • 109
  • 1
  • 5
  • 1
    I had an issue with path here on mac. So I used `baseDirectory.value` and from there I navigated to the required path which is relative. Otherwise it takes the path from home which might not be what you need. – Greedy Coder Jul 20 '17 at 12:53
  • Is there anyway I can specify from the command line?? e.g. `sbt assembly --assemblyOutputPath=Yourpath"`?? – pathikrit Dec 10 '17 at 16:50
  • 3
    assemblyOutputPath is actually less generic than target. It's literally target + assemblyJarName. How is this upvoted? – allidoiswin Feb 16 '18 at 19:41
2

A small improvement on this answer. If you need to retain the file name that is generated by assembly plugin do it as below:

assembly / assemblyOutputPath := file(s"/path/to/jar/${(assembly/assemblyJarName).value}")
0

You can set assemblyOutputPath via cmd:

sbt 'set assemblyOutputPath in assembly := new File("/path/to/package.jar")' assembly

In case you need to set multiple options - just use spaces:

sbt 'set test in assembly := {}' 'set assemblyOutputPath in assembly := new File("/path/to/package.jar")' assembly