2012-07-27 64 views
4

我的目錄結構:SBT編譯產量 「對象卡斯巴是不包com.mongodb的成員」

-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結果爲

對象卡斯巴是不包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 
+0

有趣。如果你回到''「org.mongodb」%%「casbah」%「2.3.0-RC1」''它可以工作。 – 2012-07-27 07:13:28

+0

即使是陌生人,看着我的本地常春藤緩存,我找到文件「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''。看起來好像只有來源已被下載。 – 2012-07-27 07:27:12

+0

讓我們[在聊天中繼續討論](http://chat.stackoverflow.com/rooms/14499/discussion-between-mhs-and-hrishikeshp19) – 2012-07-27 07:28:16

回答

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不起作用。

4

爲什麼你使用快照庫和舊版本的casbah?在依賴

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

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

%%標誌將在SBT斯卡拉版

選擇配置3.x版有一個里程碑

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

而且我記得在3.x的進口應改爲:

import com.mongodb.casbah._ 
+0

適合我。但是爲什麼Ivy依賴「'」org.mongodb「''與從''com.mongodb''導入之間的差異? – 2012-07-27 11:34:17

+0

不知道。似乎進口結構從以前的版本 – viktortnk 2012-07-27 16:51:27

+0

感謝您的答案,類型安全似乎比sonatype更大。 – riship89 2012-07-27 18:50:40

相關問題