简体   繁体   中英

Custom outputPath for sbt-assembly

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?

assemblyOutputPath in assembly := file("yourpath")

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}")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM