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 | |
} | |
) | |
} |
More importantly, don't forget to remove that plugin before publishing any of the projects on your machine. Otherwise a dependency on pprint will leak in the Maven POMs.
This is a terrible idea ...
Good point @sjrd, I agree it's a bad idea if you publish public libraries from a local machine (which I personally do a lot). If you let CI publish artifacts for you or if you don't publish libraries in general then this should be fine.
I updated the gist @sjrd to
- add the dependency to the Provided scope
- add a pomPostProcess to remove any dependency on pprint in the provided scope
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this in
~/.sbt/0.13/plugins/pprint.scala
to usepprint.log
everywhere! Very useful for debugging nested data structuresDon't forget to remove the debugging statements before opening a PR