Last active
July 1, 2018 20:47
-
-
Save MaxNevermind/e02ed8c185419372874e560c5a489193 to your computer and use it in GitHub Desktop.
This file contains 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
// You need Maven installed to run it. | |
lazy val mavenDependencyTree = taskKey[Unit]("Prints a Maven dependency tree") | |
mavenDependencyTree := { | |
val scalaReleaseSuffix = "_" + scalaVersion.value.split('.').take(2).mkString(".") | |
val pomXml = | |
<project> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>groupId</groupId> | |
<artifactId>artifactId</artifactId> | |
<version>1.0</version> | |
<dependencies> | |
{ | |
libraryDependencies.value.map(moduleId => { | |
val suffix = moduleId.crossVersion match { | |
case binary: sbt.librarymanagement.Binary => scalaReleaseSuffix | |
case _ => "" | |
} | |
<dependency> | |
<groupId>{moduleId.organization}</groupId> | |
<artifactId>{moduleId.name + suffix}</artifactId> | |
<version>{moduleId.revision}</version> | |
</dependency> | |
}) | |
} | |
</dependencies> | |
</project> | |
val printer = new scala.xml.PrettyPrinter(160, 2) | |
val pomString = printer.format(pomXml) | |
val pomPath = java.nio.file.Files.createTempFile("", ".xml").toString | |
val pw = new java.io.PrintWriter(new File(pomPath)) | |
pw.write(pomString) | |
pw.close() | |
println(s"Formed pom file: $pomPath") | |
import sys.process._ | |
s"mvn -f $pomPath dependency:tree".! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment