title: How to shade a dependency for a non-executable Scala Library?
body: <p>Spent a few hours trying to figure out how to do this. Over the course of it I have looked at a few seemingly promising questions but none of them seem to quite fit what I'm doing. </p>
  
  <p>I've got three library jars, let's call them <code>M</code>, <code>S</code>, and <code>H</code>. Library <code>M</code> has things like:</p>
  
  <pre><code>case class MyModel(x: Int, s: String) 
  </code></pre>
  
  <p>and then library <code>S</code> uses the play-json library, version 2.3.8, to provide implicit serializers for the classes defined by <code>M</code></p>
  
  <pre><code>trait MyModelSerializer {
      implicit val myModelFormt = Json.format[MyModel]
  }
  </code></pre>
  
  <p>Which are then bundled up together into a convenience object for importing </p>
  
  <pre><code>package object implicits extends MyModelSerializer extends FooSerizlier // etc
  </code></pre>
  
  <p>That way, in Library <code>H</code>, when it performs HTTP calls to various services it just imports <code>implicits</code> from <code>S</code> and then I call <code>Json.validate[MyModel]</code> to get back the models I need from my web services. This is all well and dandy, but I'm working on an application that's running play 2.4 and when I included <code>H</code> into the project and tried to use it I ran up against:</p>
  
  <pre><code>java.lang.NoSuchMethodError: play.api.data.validation.ValidationError.&lt;init&gt;(Ljava/lang/String;Lscala/collection/Seq;)
  </code></pre>
  
  <p>Which I believe is being caused by play 2.4 using play-json version 2.4.6. Unfortunately, these are a minor version apart and this means that trying to just use the old library like:</p>
  
  <pre><code>// In build.sbt
   "com.typesafe.play" %% "play-json" % "2.3.8" force()
  </code></pre>
  
  <p>Results in all the code in the app to fail to compile because I'm using things like <code>JsError.toJson</code> which weren't parts of play-json 2.3.8. I <em>could</em> change the 14 or so places trying to use that method, but given the exception before I have a feeling that even if I do that it's not going to help. </p>
  
  <p>Around this point I remembered that back in my maven days I could shade dependencies during my build process. So I got to thinking that if I could shade the play-json 2.3.8 dependency in <code>H</code> that that would solve the problem. Since the problem seems to be that calling <code>Json.*</code> in <code>H</code> is using the <code>Json</code> object from play-json 2.4.6. </p>
  
  <p>Unfortunately, the only thing I can find online that indicates the ability to shade is sbt-assembly. I found a <a href="https://stackoverflow.com/q/36406750/1808164">great answer</a> on how to do that for a fat jar. But I don't think I can use sbt-assembly because <code>H</code> isn't executable, it's just a library jar. I read through a <a href="https://stackoverflow.com/q/27346479/1808164">question like my own</a> but the answer refers to sbt-assembly so it doesn't help me. </p>
  
  <p><a href="https://stackoverflow.com/a/31967998/1808164">Another question seems somewhat promising</a> but I really can't follow how I would use it / where I would be placing the code itself. I also looked through the <a href="http://www.scala-sbt.org/0.13/docs/Mapping-Files.html" rel="nofollow noreferrer">sbt manual</a>, but nothing stuck out to me as being what I need. </p>
  
  <p>I can't just change <code>S</code> to use play-json 2.4.6 because we're using <code>H</code> in a play 2.3 application as well. <em>So it needs to be able to be used in both.</em></p>
  
  <p>Right now the only thing I can really think to do if I can't get some kind of shading done is to make <code>H</code> not use <code>S</code> and to instead require some kind of serializer/deserializer implicitly and then wire in the appropriate json (dee)serializer. So here I am asking about how to properly shade with sbt with something that isn't an executable jar because I only want to do a re-write if I absolutely have to. If I missed something (like sbt-assembly being able to shade for non-executable jars as well), I'll take that as an answer if you can point me to the docs I must have missed.</p>