Skip to content

Commit

Permalink
ShadingPlugin: use full deps, including platform
Browse files Browse the repository at this point in the history
Otherwise, native and sjs dependencies will not be found and included
in the output jar.
  • Loading branch information
kitbellew committed Jul 21, 2023
1 parent 2c09f49 commit c9e3116
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ enablePlugins(ShadingPlugin)

// Add the dependencies to shade along the other (non-shaded) ones
libraryDependencies += "io.argonaut" %% "argonaut" % "6.2"
libraryDependencies += "org.scalameta" %%% "trees" % "4.8.5"

// Tell the plugin to shade some dependencies.
// This also shades all their transitive dependencies, except those
// that are also brought by non-shaded dependencies.
// This merges those dependencies JARs in our output JAR, along with our
// classes.
shadedModules += "io.argonaut" %% "argonaut"
// NB: the version itself doesn't matter but `%%` vs `%%%` does
shadedDependencies += "io.argonaut" %% "argonaut" % "<ignored>"
shadedDependencies += "org.scalameta" %%% "trees" % "<ignored>"

// Tell the plugin to rename some namespaces in the output JAR.
// This renames any of our classes in this namespace, and adjusts
Expand Down
26 changes: 12 additions & 14 deletions src/main/scala/coursier/ShadingPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ object ShadingPlugin extends AutoPlugin {
object autoImport {
// to be set by users
val shadedModules = settingKey[Set[OrganizationArtifactName]]("")
val shadedDependencies = settingKey[Set[ModuleID]]("")
val shadingRules = taskKey[Seq[Rule]]("")
val validNamespaces = taskKey[Set[String]]("")
val validEntries = taskKey[Set[String]]("")
Expand Down Expand Up @@ -134,9 +135,17 @@ object ShadingPlugin extends AutoPlugin {
assert(unrecognized.isEmpty)
}

private lazy val shadedOrgNames = Def.setting[Set[(String, String)]] {
val scalaModuleInfoOpt = scalaModuleInfo.value
val allShadedDeps = shadedDependencies.value.iterator ++
shadedModules.value.iterator.map(_ % "foo")
allShadedDeps.map(orgName(_, scalaModuleInfoOpt)).toSet
}

override lazy val projectSettings = Def.settings(

shadedModules := Set.empty,
shadedDependencies := Set.empty,
shadingRules := Nil,
validNamespaces := Set.empty,
validEntries := Set.empty,
Expand All @@ -145,10 +154,7 @@ object ShadingPlugin extends AutoPlugin {

shadedJars := {
val scalaModuleInfoOpt = scalaModuleInfo.value
val shadedModules0 = shadedModules.value.map { orgName0 =>
val modId = orgName0 % "foo"
orgName(modId, scalaModuleInfoOpt)
}
val shadedModules0 = shadedOrgNames.value

val thisOrgName = orgName(projectID.value, scalaModuleInfoOpt)
val classpathTypes = Keys.classpathTypes.value
Expand Down Expand Up @@ -228,11 +234,7 @@ object ShadingPlugin extends AutoPlugin {
},

deliverLocal := {
val scalaModuleInfoOpt = scalaModuleInfo.value
val shadedModules0 = shadedModules.value.map { orgName0 =>
val modId = orgName0 % "foo"
orgName(modId, scalaModuleInfoOpt)
}
val shadedModules0 = shadedOrgNames.value

val file = deliverLocal.value
updateIvyXml(file, shadedModules0)
Expand All @@ -241,12 +243,8 @@ object ShadingPlugin extends AutoPlugin {

pomPostProcess := {
val previous = pomPostProcess.value
val scalaModuleInfoOpt = scalaModuleInfo.value

val shadedModules0 = shadedModules.value.map { orgName0 =>
val modId = orgName0 % "foo"
orgName(modId, scalaModuleInfoOpt)
}
val shadedModules0 = shadedOrgNames.value

// Originally based on https://github.com/olafurpg/coursier-small/blob/408528d10cea1694c536f55ba1b023e55af3e0b2/build.sbt#L44-L56
val transformer = new RuleTransformer(new RewriteRule {
Expand Down

0 comments on commit c9e3116

Please sign in to comment.