2

I'm using two files for my build: build.sbt and assembly.sbt (for building fat jars using sbt-assembly plugin). I have some vals defined in build.sbt. Let's just say I'm doing some custom tasks that depend on them. However, I noticed that vals defined in build.sbt are not visible in assembly.sbt. So I end up duplicating code in those two files. How do I configure it such that assembly.sbt can see the vals in build.sbt?

Thanks!

4

1 回答 1

2

目前,*.sbt文件中的 val 旨在以命名空间分隔。我们已经讨论过是否拥有全局命名空间的优点,但最终将它们分开会使事情更加一致。

在 build.sbt之间共享 val 和设置的“sbt”方式是:

  • 创建一个这样做的插件。
  • project/在执行此操作的目录中创建一个“库” 。

对于选项 #2,您可以执行以下操作:

项目/lib.scala

package mylib

object MyStuff {
   val foo = "hi"
}

构建.sbt

import mylib.MyStuff

// Just reference .scala code from the project/ directory.
name := MyStuff.foo

希望有帮助!

于 2015-01-15T16:29:25.270 回答