简体   繁体   English

为什么sbt控制台在多模块项目中看不到子项目的包?

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

This is my project/Build.scala : 这是我的项目/ 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
  )
}

This seems to be compiling my project just fine, but when I go into the console, I can't import any of the code that just got compiled?! 这似乎正在编译我的项目就好了,但是当我进入控制台时,我无法导入任何刚刚编译的代码?!

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

What am I doing wrong here? 我在这做错了什么? Trying to look at the usage, I don't see a way to say which subproject to load while in the console 试图查看用法,我没有看到在控制台中说明要加载哪个子项目的方法

$ 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

There's the solution from @Alexey-Romanov to start the console task in the project the classes to import are in. 来自@Alexey-Romanov的解决方案是在要导入的类的项目中启动console任务。

sbt sutils/console

There's however another solution that makes the root sutils project depend on the other core . 然而,另一个解决方案使root sutils项目依赖于另一个core Use the following snippet to set up the project - note dependsOn core that will bring the classes from the core project to sutils 's namespace. 使用以下代码片段来设置项目 - 注意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

BTW, you should really use a simpler build.sbt for your use case as follows: 顺便说一句,您应该使用更简单的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
)

You could make it even easier when you'd split the build to two build.sbt s, each for the projects. 当你将构建拆分为两个build.sbt时,你可以使它更容易,每个build.sbt用于项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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