简体   繁体   中英

Scala jar in Maven project: Failure to find org.mongodb:casbah_2.12:jar:3.1.1

Scala and sbt newbie here. I created a Scala sbt project that uses casbah

libraryDependencies += "org.mongodb" %% "casbah" % "3.1.1"

to query a mongodb and return results as a map. I want to use this code in my Java maven project to manipulate the results that I get from querying the database.

I added this to my build.sbt file:

publishMavenStyle := true

publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath + "/.m2/repository")))

to install a jar file in my .m2 local repo. Here is the output when I do 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

I then imported this dependency in my pom file:

<dependency>
    <groupId>edu.cmu.cs.mvelezce</groupId>
    <artifactId>mongo_2.12</artifactId>
    <version>0.1.0-SNAPSHOT</version>
</dependency>

When I run mvn compile , I get the following error:

[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]

I know that casbah has several modules and I can import just a few instead of all of them. However, following the documentation in Casbah , I add the enterie library. I also looked at Maven Central and this version of casbah does not have a jar; only the independent modules. I added some of those modules in my pom, but I still got the same error as above. Maven is looking for that complete jar file.

Is there a way to fix this? I thought I could only add the Scala dependencies that I need in my build.sbt file, but I got compilation errors when I did that. Does anybody have sugguestions?

Thanks!

You need to ensure that the Casbah dependency is of type pom in your project. Eg in your pom.xml add the following:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>casbah_2.11</artifactId>
    <version>3.1.1</version>
    <type>pom</type>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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