insan-e
insan-e

Reputation: 3921

Sbt-assembly, Ivy, classpath

I'm struggling with this for a long time, so any help would be appreciated.
I have a common library myCommonLib which has a dependency that I need to shade with sbt-assembly.
When I publish it to my local Ivy repo, I get 2 versions, a "normal" one (as usual), and a shaded one (with all dependencies bundled), with "-assembly" appended, of course.

The problem is when I use my "normal" dependency, I get NoClassDefFoundError that refers to shaded version!!!

I tried to remove it completely from classpath like this:

dependencyClasspath in Runtime := {
  val allFiles: Seq[Attributed[File]] = (dependencyClasspath in Runtime).value
  allFiles.filterNot(_.data.getName.toLowerCase.contains("-assembly"))
}

but it doesn't work, still the same error.

However, when I remove it (comment out) from the Ivy XML it does work:

<artifact name="myCommonLib_2.11" type="jar" ext="jar" conf="compile,runtime,test,provided,optional,sources,docs,pom" e:classifier="assembly"/>

What am I missing?

Upvotes: 0

Views: 477

Answers (2)

insan-e
insan-e

Reputation: 3921

I've managed to make it work, for now...
It seems to work when I specify the exact artifact, like this:

val myCommonLibArtifact = Artifact(
  name="myCommonLib", `type`="jar", extension="jar", classifier=None,
  configurations=Seq(Compile), url=None, extraAttributes=Map())

libraryDependencies ++= Seq(
  "ba.sake" %% "myCommonLib" % "0.0.1" artifacts (myCommonLibArtifact)      
)

Upvotes: 1

λ Allquantor λ
λ Allquantor λ

Reputation: 1131

You could exclude it in your build sbt by doing this

libraryDependencies ++= Seq(
  "some" % "myCommonLib" % "1.0" excludeAll(
      ExclusionRule(organization = "yourOrganisation", name = "dependency name"),
      ...
)

Here the necessary documentation: http://www.scala-sbt.org/0.12.2/api/sbt/ExclusionRule.html

Upvotes: 0

Related Questions