Last active
October 17, 2017 02:28
-
-
Save olafurpg/cabbcc58105dac05d8b9644dcb406e0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._, Keys._ | |
import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _} | |
import scala.xml.transform.{RewriteRule, RuleTransformer} | |
import sbt.plugins.JvmPlugin | |
object PPrintPlugin extends AutoPlugin { | |
override def requires = JvmPlugin | |
override def trigger: PluginTrigger = AllRequirements | |
override def projectSettings: Seq[Def.Setting[_]] = List( | |
libraryDependencies ++= { | |
if (scalaVersion.value.startsWith("2.")) | |
List("com.lihaoyi" %% "pprint" % "0.5.2" % Provided) | |
else Nil | |
}, | |
// (optional), if you publish libraries from your local computer then make | |
// sure to exclude pprint from your published POM. | |
pomPostProcess := { node => | |
new RuleTransformer(new RewriteRule { | |
private def isPPrint(node: XmlNode): Boolean = { | |
def matchesArtifactId(node: XmlNode) = | |
node.label == "artifactId" && node.text.startsWith("pprint_") | |
def matchesScope(node: XmlNode) = | |
node.label == "scope" && node.text == "provided" | |
node.label == "dependency" && | |
node.child.exists(matchesArtifactId) && | |
node.child.exists(matchesScope) | |
} | |
override def transform(node: XmlNode): XmlNodeSeq = node match { | |
case e: Elem if isPPrint(node) => Text("") | |
case _ => node | |
} | |
}).transform(pomPostProcess.value(node)).head | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated the gist @sjrd to