其他答案中有很多含糊不清的内容,或者涉及到更旧版本的 sbt(即 0.12.x),但似乎没有人真正回答这个问题。
鉴于我有一个文件夹,并且我已经运行:
sbt new scala/scala-seed.g8
name [Scala Seed Project]: one
sbt new scala/scala-seed.g8
name [Scala Seed Project]: two
我现在有一个如下所示的目录结构:
8 ./one/build.sbt
8 ./one/...
8 ./two/build.sbt
8 ./two/...
80 .
好的,所以我现在去改变example
命名空间在one
and two
,所以代码在相应的中看起来像这样Hello.scala
files:
package example.two
object Hello extends Greeting {
}
trait Greeting {
lazy val greeting: String = "hello two"
}
and:
package example.one
object Hello extends Greeting with App {
println(greeting)
println(example.two.Hello.greeting)
}
trait Greeting {
lazy val greeting: String = "hello one"
}
现在,我到底该如何编写代码one
编译并运行?
从我读过的内容来看,我似乎应该做类似的事情one/project/Dependencies.scala
:
import sbt._
object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
lazy val two = ProjectRef(file("../two"), "two") <------------ ADD THIS
}
这在one/build.sbt
:
import Dependencies._
lazy val root = (project in file("."))
.dependsOn(two) <--------------------- ADD THIS
.settings(
inThisBuild(List(
organization := "com.example",
scalaVersion := "2.12.7",
version := "0.1.0-SNAPSHOT"
)),
name := "one",
libraryDependencies += scalaTest % Test
)
...但它不起作用:
92-168-1-4:one doug$ sbt run
[info] Loading settings for project global-plugins from idea.sbt ...
[info] Loading global plugins from /Users/doug/.sbt/1.0/plugins
[info] Loading project definition from /Users/doug/tmp/one/project
[info] Compiling 1 Scala source to /Users/doug/tmp/one/project/target/scala-2.12/sbt-1.0/classes ...
[info] Done compiling.
[info] Loading settings for project root from build.sbt ...
[info] Loading project definition from /Users/doug/tmp/two/project
[info] Loading settings for project root from build.sbt ...
[error] java.lang.RuntimeException: No project 'two' in 'file:/Users/doug/tmp/two/'.
[error] Valid project IDs: root
[error] at scala.sys.package$.error(package.scala:26)
“[错误]有效项目 ID:root”是什么意思?
我这样做完全错误吗?应该例如。正在使用sbt publishLocal
或者其他的东西?
我找不到任何有意义的文档来说明您应该如何使用本地库not当前项目的子模块;我错过了 sbt 文档的一部分吗?
该部分关于Inter-project dependencies
in 1.x 文档 https://www.scala-sbt.org/1.x/docs/sbt-reference.pdf似乎根本没有解释这一点,它只是谈论跟踪引用......
help?