这是我的项目/ Build.scala:
package sutils
import sbt._
import Keys._
object SutilsBuild extends Build {
scalaVersion in ThisBuild := "2.10.0"
val scalazVersion = "7.0.6"
lazy val sutils = Project(
id = "sutils",
base = file(".")
).settings(
test := { },
publish := { }, // skip publishing for this root project.
publishLocal := { }
).aggregate(
core
)
lazy val core = Project(
id = "sutils-core",
base = file("sutils-core")
).settings(
libraryDependencies += "org.scalaz" % "scalaz-core_2.10" % scalazVersion
)
}
Run Code Online (Sandbox Code Playgroud)
这似乎正在编译我的项目就好了,但是当我进入控制台时,我无法导入任何刚刚编译的代码?!
$ sbt console
scala> import com.github.dcapwell.sutils.validate.Validation._
<console>:7: error: object github is not a member of package com
import com.github.dcapwell.sutils.validate.Validation._
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?试图查看用法,我没有看到在控制台中说明要加载哪个子项目的方法
$ sbt about
[info] Loading project definition from /src/sutils/project
[info] Set current project to sutils (in build file:/src/sutils/)
[info] This is sbt 0.13.1
[info] The current project is {file:/src/sutils/}sutils 0.1-SNAPSHOT
[info] The current project is built against Scala 2.10.3
[info] Available Plugins: org.sbtidea.SbtIdeaPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.10.3
Run Code Online (Sandbox Code Playgroud)
Jac*_*ski 15
来自@Alexey-Romanov的解决方案console是在项目中启动要导入的类的任务.
sbt sutils/console
Run Code Online (Sandbox Code Playgroud)
然而,另一个解决方案使根sutils项目依赖于另一个core.使用以下代码段来设置项目 - 请注意dependsOn core,这会将core项目中的类带到sutils命名空间.
lazy val sutils = Project(
id = "sutils",
base = file(".")
).settings(
test := { },
publish := { }, // skip publishing for this root project.
publishLocal := { }
).aggregate(
core
).dependsOn core
Run Code Online (Sandbox Code Playgroud)
顺便说一下,您应该使用更简单build.sbt的用例,如下所示:
scalaVersion in ThisBuild := "2.10.0"
val scalazVersion = "7.0.6"
lazy val sutils = project.in(file(".")).settings(
test := {},
publish := {}, // skip publishing for this root project.
publishLocal := {}
).aggregate(core).dependsOn(core)
lazy val core = Project(
id = "sutils-core",
base = file("sutils-core")
).settings(
libraryDependencies += "org.scalaz" %% "scalaz-core" % scalazVersion
)
Run Code Online (Sandbox Code Playgroud)
当你将构建拆分为两个build.sbts时,你可以使它更容易,每个都用于项目.
| 归档时间: |
|
| 查看次数: |
4119 次 |
| 最近记录: |