【问题标题】:sbt compile yields "object casbah is not a member of package com.mongodb"sbt compile 产生“object casbah 不是包 com.mongodb 的成员”
【发布时间】:2013-12-24 22:16:34
【问题描述】:

我的目录结构:

-build.sbt
-src
--main
---scala
----MongoConnect.scala
-lib

我的build.sbt:

name := "mongodb-experiments"

version := "0.1"

libraryDependencies ++= Seq(
  "com.mongodb.casbah" %% "casbah" % "3.0.0-SNAPSHOT"
)

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

我的 MongoConnect.scala 程序:

import com.mongodb.casbah.Imports._
object MongoConnect{
  def main(args: Array[String]){
    println("Hello Mongo")
  }
}

为什么sbt compile 会导致

object casbah 不是 com.mongodb 包的成员

?

sbt compile
[info] Set current project to mongodb-experiments (in build file:/Users/hrishikeshparanjape/git-public/mongodb-experiments/)
[info] Updating {file:/Users/hrishikeshparanjape/git-public/mongodb-experiments/}default-fc358e...
[info] Resolving org.scala-lang#scala-library;2.9.1 ...
[info] Resolving com.mongodb.casbah#casbah_2.9.1;3.0.0-SNAPSHOT ...
[info] Resolving com.mongodb.casbah#casbah-util_2.9.1;3.0.0-SNAPSHOT ...
[info] Resolving org.slf4j#slf4j-api;1.6.0 ...
[info] Resolving org.mongodb#mongo-java-driver;2.7.2 ...
[info] Resolving org.scalaj#scalaj-collection_2.9.1;1.2 ...
[info] Resolving org.scala-tools.time#time_2.8.0;0.2 ...
[info] Resolving joda-time#joda-time;1.6 ...
[info] Resolving com.mongodb.casbah#casbah-commons_2.9.1;3.0.0-SNAPSHOT ...
[info] Resolving com.mongodb.casbah#casbah-core_2.9.1;3.0.0-SNAPSHOT ...
[info] Resolving com.mongodb.casbah#casbah-query_2.9.1;3.0.0-SNAPSHOT ...
[info] Resolving com.mongodb.casbah#casbah-gridfs_2.9.1;3.0.0-SNAPSHOT ...
[info] Done updating.
[info] Compiling 1 Scala source to /Users/hrishikeshparanjape/git-public/mongodb-experiments/target/scala-2.9.1/classes...
[error] /Users/hrishikeshparanjape/git-public/mongodb-experiments/src/main/scala/MongoConnect.scala:1: object casbah is not a member of package com.mongodb
[error] import com.mongodb.casbah.Imports._
[error]                    ^
[error] one error found
[error] {file:/Users/hrishikeshparanjape/git-public/mongodb-experiments/}default-fc358e/compile:compile: Compilation failed
[error] Total time: 7 s, completed Jul 26, 2012 11:53:35 PM

【问题讨论】:

  • 有趣。如果你回到"org.mongodb" %% "casbah" % "2.3.0-RC1",它可以工作。
  • 甚至陌生人,查看我本地的常春藤缓存,我找到了文件org.mongodb\cashbah-core_2.9.1\jars\casbah-core_2.9.1-2.3.0-RC1.jar,但对于3.0.0-SNAPSHOT,我只找到com.mongodb.casbah\casbah-core_2.9.1\jars\casbah-core_2.9.1-3.0.0-SNAPSHOT-sources.jar。看起来好像只下载了源代码。

标签: mongodb scala sbt


【解决方案1】:

您为什么将快照存储库与旧版本的 casbah 一起使用?

libraryDependencies ++= Seq(
  "org.mongodb" %% "casbah" % "2.4.1"
)

resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases/"

%% 登录依赖会选择在 sbt scala 版本中配置

对于 3.x 版本有一个里程碑

libraryDependencies ++= Seq(
      "org.mongodb" %% "casbah" % "3.0.0-M2"
    )

我记得在 3.x 中导入应该改为:

import com.mongodb.casbah._

【讨论】:

  • 为我工作。但是为什么 Ivy 依赖 "org.mongodb" 和从 com.mongodb 的导入之间存在差异?
  • 不知道。似乎导入结构来自以前的版本
  • 感谢您的回答,typesafe 似乎比 sonatype 更大。
【解决方案2】:

修改你的 build.sbt 文件为:

name := "mongodb-experiments"

version := "0.1"

libraryDependencies ++= Seq(
  "com.mongodb.casbah" % "casbah_2.9.0" % "2.2.0-SNAPSHOT"
)

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

由于某种原因,3.0.0 不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-18
    • 2011-12-06
    • 2020-10-27
    • 1970-01-01
    • 2020-04-20
    • 2014-12-14
    相关资源
    最近更新 更多