Skip to content

Commit 0fdb861

Browse files
committed
#680 Shade ANTLR for cobol-parser so that it won't clash with Spark's ANTLR runtime.
Also, the shading of dependent libraries is improved for 'sbt assembly'.
1 parent aa95886 commit 0fdb861

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

build.sbt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,34 @@ lazy val cobrix = (project in file("."))
6161
.aggregate(cobolParser, cobolConverters, sparkCobol)
6262

6363
lazy val cobolParser = (project in file("cobol-parser"))
64+
.enablePlugins(ShadingPlugin)
65+
.enablePlugins(AutomateHeaderPlugin)
6466
.settings(
6567
name := "cobol-parser",
6668
libraryDependencies ++= CobolParserDependencies :+ getScalaDependency(scalaVersion.value),
69+
shadedDependencies ++= CobolParserShadedDependencies,
70+
shadingRules ++= Seq (
71+
ShadingRule.moveUnder("org.antlr.v4.runtime", "za.co.absa.cobrix.cobol.parser.shaded")
72+
),
73+
validNamespaces ++= Set("za"),
6774
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
68-
assemblySettings
69-
)
70-
.settings(
75+
assemblySettings,
7176
jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:cobol-parser Jacoco Report"),
7277
jacocoExcludes := commonJacocoExcludes
73-
).enablePlugins(AutomateHeaderPlugin)
78+
)
7479

7580
lazy val cobolConverters = (project in file("cobol-converters"))
81+
.dependsOn(cobolParser)
7682
.disablePlugins(sbtassembly.AssemblyPlugin)
83+
.enablePlugins(AutomateHeaderPlugin)
7784
.settings(
7885
name := "cobol-converters",
7986
libraryDependencies ++= CobolConvertersDependencies :+ getScalaDependency(scalaVersion.value),
8087
// No need to publish this artifact since it has test only at the moment
8188
publishArtifact := false,
8289
publish := {},
8390
publishLocal := {}
84-
).dependsOn(cobolParser)
85-
.enablePlugins(AutomateHeaderPlugin)
91+
)
8692

8793
lazy val sparkCobol = (project in file("spark-cobol"))
8894
.settings(
@@ -144,7 +150,11 @@ lazy val assemblySettings = Seq(
144150
assembly / assemblyOption:= (assembly / assemblyOption).value.copy(includeScala = false),
145151
assembly / assemblyShadeRules:= Seq(
146152
// Spark may rely on a different version of ANTLR runtime. Renaming the package helps avoid the binary incompatibility
147-
ShadeRule.rename("org.antlr.**" -> "za.co.absa.cobrix.shaded.org.antlr.@1").inAll,
153+
ShadeRule.rename("org.antlr.**" -> "za.co.absa.cobrix.cobol.parser.shaded.org.antlr.@1").inAll,
154+
// Shading all 3rd party libraries used by 'spark-cobol' in order to avoid binary conflicts.
155+
ShadeRule.rename("macrocompat.**" -> "za.co.absa.cobrix.spark.cobol.shaded.macrocompat.@1").inAll,
156+
ShadeRule.rename("scodec.**" -> "za.co.absa.cobrix.spark.cobol.shaded.scodec.@1").inAll,
157+
ShadeRule.rename("shapeless.**" -> "za.co.absa.cobrix.spark.cobol.shaded.shapeless.@1").inAll,
148158
// The SLF4j API and implementation are provided by Spark
149159
ShadeRule.zap("org.slf4j.**").inAll
150160
),

project/Dependencies.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object Dependencies {
7272

7373
val CobolParserDependencies: Seq[ModuleID] = Seq(
7474
// compile
75-
"org.scodec" %% "scodec-core" % scodecCoreVersion,
75+
"org.scodec" %% "scodec-core" % scodecCoreVersion excludeAll(ExclusionRule(organization = "org.scala-lang")),
7676
"org.antlr" % "antlr4-runtime" % antlrValue,
7777
"org.slf4j" % "slf4j-api" % slf4jVersion,
7878

@@ -82,6 +82,10 @@ object Dependencies {
8282
"org.slf4j" % "slf4j-simple" % slf4jVersion % Test
8383
)
8484

85+
val CobolParserShadedDependencies: Set[ModuleID] = Set(
86+
"org.antlr" % "antlr4-runtime" % slf4jVersion
87+
)
88+
8589
val CobolConvertersDependencies: Seq[ModuleID] = Seq(
8690
// compile
8791
"org.slf4j" % "slf4j-api" % slf4jVersion,

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
33
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
44
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
55
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
6+
addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.1.5")
67

78
// sbt-jacoco - workaround related dependencies required to download
89
lazy val ow2Version = "9.5"

0 commit comments

Comments
 (0)