gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:54:21 28 4
gpt4 key购买 nike

这是我的项目/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

然而,还有另一种解决方案使根 sutils项目依赖于其他 core .使用以下代码段设置项目 - 注意 dependsOn core这将带来 core 中的类(class)项目至 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 时,您可以使其变得更加容易。 s,每个为项目。

关于scala - 为什么 sbt 控制台在多模块项目中看不到来自子项目的包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24299043/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com