From 1bc6079404e6e961a905de0ca7aadddb555a16fd Mon Sep 17 00:00:00 2001 From: Dmitry Karlinsky Date: Tue, 13 Jun 2023 09:27:22 +0300 Subject: [PATCH] netty-shading: only enable ShadingPlugin if `publish.shaded` property 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 --- build.sbt | 8 ++++---- project/BuildHelper.scala | 6 +----- project/Shading.scala | 10 +++++++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index 85acd59312..71beeca1f3 100644 --- a/build.sbt +++ b/build.sbt @@ -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( @@ -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( diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 6154e7803f..bc1e89a24b 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -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( diff --git a/project/Shading.scala b/project/Shading.scala index 2b4941bfb1..af86cdcdb3 100644 --- a/project/Shading.scala +++ b/project/Shading.scala @@ -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 }