Search code examples
javascalasbtivysbt-assembly

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?


Solution

  • 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)      
    )