Skip to content

Commit

Permalink
netty-shading: only enable ShadingPlugin if publish.shaded property…
Browse files Browse the repository at this point in the history
… is true (#2251)

* netty-shading: only enable ShadingPlugin if `publish.shaded` property is true

* Scala 2 syntax for the build files

---------

Co-authored-by: Daniel Vigovszky <[email protected]>
  • Loading branch information
dkarlinsky and vigoo authored Jun 13, 2023
1 parent 8ceaf03 commit 1bc6079
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ lazy val root = (project in file("."))
)

lazy val zioHttp = (project in file("zio-http"))
.enablePlugins(ShadingPlugin)
.enablePlugins(Shading.plugins() : _*)
.settings(stdSettings("zio-http"))
.settings(publishSetting(true))
.settings(settingsWithHeaderLicense)
.settings(meta)
.settings(Shading.shadingSettings(shadingEnabled))
.settings(Shading.shadingSettings())
.settings(
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= netty ++ Seq(
Expand Down Expand Up @@ -153,10 +153,10 @@ lazy val zioHttpExample = (project in file("zio-http-example"))
.dependsOn(zioHttp, zioHttpCli)

lazy val zioHttpTestkit = (project in file("zio-http-testkit"))
.enablePlugins(ShadingPlugin)
.enablePlugins(Shading.plugins() : _*)
.settings(stdSettings("zio-http-testkit"))
.settings(publishSetting(true))
.settings(Shading.shadingSettings(shadingEnabled))
.settings(Shading.shadingSettings())
.settings(
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= netty ++ Seq(
Expand Down
6 changes: 1 addition & 5 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ object BuildHelper extends ScalaSettings {
)

private def shadedSuffix = {
if (shadingEnabled) "-shaded" else ""
}

def shadingEnabled = {
sys.props.get("publish.shaded").fold(false)(_.toBoolean)
if (Shading.shadingEnabled) "-shaded" else ""
}

def runSettings(className: String = "example.HelloWorld") = Seq(
Expand Down
10 changes: 9 additions & 1 deletion project/Shading.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import Dependencies._
import coursier.ShadingPlugin
import coursier.ShadingPlugin.autoImport._
import sbt.Plugins

object Shading {
def shadingSettings(enabled: Boolean = true) = if(enabled) {
def shadingSettings() = if (shadingEnabled) {
Seq(
shadedModules ++= (netty :+ `netty-incubator`).map(_.module).toSet,
shadingRules += ShadingRule.rename("io.netty.**", "zio.http.shaded.netty.@1"),
validNamespaces += "zio",
)
} else Nil

def shadingEnabled = {
sys.props.get("publish.shaded").fold(false)(_.toBoolean)
}

def plugins(): Seq[Plugins] = if(shadingEnabled) Seq(ShadingPlugin) else Nil
}

0 comments on commit 1bc6079

Please sign in to comment.