SexyNerd
SexyNerd

Reputation: 1124

How to solve 2 classes in dependency with exact same path&name?

I'm using SBT to manage dependencies. I added 2 jars AAA and BBB into my project. However, both AAA and BBB have a class with exact same name and path like com.ccc.ddd.eee.fff.foo.java.

Now, the compiler does NOT complain. However, when I import foo.java, it always comes from jar AAA although, unfortunately, I want it to come from jar BBB.

Any suggestions about how to solve this puzzle? Thank you in advance.

EDIT: I was using libraryDependencies +=, managed dependencies.

Upvotes: 1

Views: 224

Answers (1)

Mike Slinn
Mike Slinn

Reputation: 8407

You didn't say how the 2 jars were added; it would be helpful to see your build.sbt.

That said, the classpath is affected by the order in which you list the dependencies. If you are using unmanaged dependencies, and you want a specific version of a class to be found, list that library dependency first.

If they were specified as managed dependencies, it is more common to try something like:

libraryDependencies += "foo" % "bar" % "x.y.z" exclude("org.domain", "AAA")

or:

ivyXML :=
  <dependencies>
    <dependency org="org.domain" name="AAA" rev="x.y.z">
      <exclude module="activation"/>
    </dependency>
  </dependencies>

There is more information here: http://www.scala-sbt.org/release/docs/Library-Management.html

Upvotes: 1

Related Questions