Skip to content

Commit

Permalink
Add PomFilter to filter out "scoverage" and "silencer"
Browse files Browse the repository at this point in the history
Motivation:

- "provided" does not remove dependencies from a pom.xml
- use a snippet from typelevel#739 to exclude undesired dependencies
- apply PomFilter to exlude scoverage too.
  • Loading branch information
kubum committed Feb 11, 2020
1 parent 0a9b094 commit 9fab372
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
20 changes: 6 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,14 @@ val commonSettings = Seq(
|limitations under the License.""".stripMargin
)
),
// For evicting Scoverage out of the generated POM
// See: https://github.com/scoverage/sbt-scoverage/issues/153
pomPostProcess := { (node: xml.Node) =>
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] = node match {
case e: Elem
if e.label == "dependency" && e.child
.exists(child => child.label == "groupId" && child.text == "org.scoverage") =>
Nil
case _ => Seq(node)
}
}).transform(node).head
},
addCompilerPlugin(("org.typelevel" %% "kind-projector" % "0.11.0").cross(CrossVersion.full)),
mimaFailOnNoPrevious := false
)
) ++
// For evicting Scoverage out of the generated POM
// See: https://github.com/scoverage/sbt-scoverage/issues/153
PomFilter.filterOutDependencyFromGeneratedPomXml("groupId" -> "org\\.scoverage".r) ++
PomFilter.filterOutDependencyFromGeneratedPomXml("groupId" -> "com\\.github\\.ghik".r,
"artifactId" -> "silencer-lib".r)

val mimaSettings = Seq(
mimaPreviousArtifacts := {
Expand Down
41 changes: 41 additions & 0 deletions project/PomFilter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import scala.util.matching.Regex
import scala.xml.Elem
import scala.xml.transform.{RewriteRule, RuleTransformer}
import sbt.Keys.pomPostProcess

object PomFilter {
/**
* Filter out dependencies from the generated `pom.xml`.
*
* E.g. to exclude Scoverage:
* {{{
* filterOutDependencyFromGeneratedPomXml("groupId" -> "org\\.scoverage".r)
* }}}
*
* Or to exclude based on both `groupId` and `artifactId`:
* {{{
* filterOutDependencyFromGeneratedPomXml("groupId" -> "io\\.estatico".r, "artifactId" -> "newtype".r)
* }}}
*/
def filterOutDependencyFromGeneratedPomXml(conditions: (String, Regex)*) = {
def shouldExclude(e: Elem) =
e.label == "dependency" && {
conditions.forall { case (key, regex) =>
e.child.exists(child => child.label == key && regex.findFirstIn(child.text).isDefined)
}
}

if (conditions.isEmpty) Nil else {
Seq(
pomPostProcess := { (node: xml.Node) =>
new RuleTransformer(new RewriteRule {
override def transform(node: xml.Node): Seq[xml.Node] = node match {
case e: Elem if shouldExclude(e) => Nil
case _ => Seq(node)
}
}).transform(node).head
},
)
}
}
}

0 comments on commit 9fab372

Please sign in to comment.