Scala和sbt新手在这里。我创建了一个使用casbah的Scala sbt项目
libraryDependencies += "org.mongodb" %% "casbah" % "3.1.1"
查询mongodb并以地图形式返回结果。我想在Java Maven项目中使用此代码来处理从查询数据库中获得的结果。
我将其添加到build.sbt文件中:
publishMavenStyle := true
publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath + "/.m2/repository")))
在我的.m2本地存储库中安装jar文件。这是我执行
sbt publish
时的输出:> publish
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT-sources.jar ...
[info] Done packaging.
[info] Main Scala API documentation to /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/api...
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT.jar ...
[info] Done packaging.
[info] Wrote /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT.pom
[info] :: delivering :: edu.cmu.cs.mvelezce#mongo_2.12;0.1.0-SNAPSHOT :: 0.1.0-SNAPSHOT :: integration :: Sun Apr 09 13:58:46 EDT 2017
[info] delivering ivy file to /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/ivy-0.1.0-SNAPSHOT.xml
model contains 9 documentable templates
[info] Main Scala API documentation successful.
[info] Packaging /Users/miguelvelez/Documents/Programming/Scala/Projects/mongo/target/scala-2.12/mongo_2.12-0.1.0-SNAPSHOT-javadoc.jar ...
[info] Done packaging.
[info] published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT.pom
[info] published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT.jar
[info] published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT-sources.jar
[info] published mongo_2.12 to /Users/miguelvelez/.m2/repository/edu/cmu/cs/mvelezce/mongo_2.12/0.1.0-SNAPSHOT/mongo_2.12-0.1.0-SNAPSHOT-javadoc.jar
[success] Total time: 3 s, completed Apr 9, 2017 1:58:49 PM
然后,我将此依赖项导入了pom文件:
<dependency>
<groupId>edu.cmu.cs.mvelezce</groupId>
<artifactId>mongo_2.12</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
运行
mvn compile
时,出现以下错误:[ERROR] Failed to execute goal on project performance-mapper: Could not resolve dependencies for project edu.cmu.cs.mvelezce:performance-mapper:jar:0.1.0-SNAPSHOT: Failure to find org.mongodb:casbah_2.12:jar:3.1.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
我知道casbah有几个模块,我只能导入几个模块,而不是全部模块。但是,按照Casbah中的文档,我添加了enterie库。我还看着Maven Central,这个版本的casbah没有罐子。仅独立模块。我在pom中添加了其中一些模块,但是仍然遇到与上面相同的错误。 Maven正在寻找完整的jar文件。
有没有办法来解决这个问题?我以为我只能在build.sbt文件中添加所需的Scala依赖项,但是这样做时出现编译错误。有人建议吗?
谢谢!
最佳答案
您需要确保在项目中,Casbah依赖项的类型为pom
。例如,在您的pom.xml中添加以下内容:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>casbah_2.11</artifactId>
<version>3.1.1</version>
<type>pom</type>
</dependency>