簡體   English   中英

為什么sbt控制台在多模塊項目中看不到子項目的包?

[英]Why does sbt console not see packages from subproject in multi-module project?

這是我的項目/ 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
  )
}

這似乎正在編譯我的項目就好了,但是當我進入控制台時,我無法導入任何剛剛編譯的代碼?!

$ 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._

我在這做錯了什么? 試圖查看用法,我沒有看到在控制台中說明要加載哪個子項目的方法

$ 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

來自@Alexey-Romanov的解決方案是在要導入的類的項目中啟動console任務。

sbt sutils/console

然而,另一個解決方案使root 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

順便說一句,您應該使用更簡單的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
)

當你將構建拆分為兩個build.sbt時,你可以使它更容易,每個build.sbt用於項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM