鉴于x + x + x + x
中对jar的引用,如何获取有关相应Ivy包的常春藤元数据?
就我~/.ivy2/cache
而言,这是我能得到的。我在Scala中写过这个,但Java解决方案也可以。我相信如果代码中显示的错误得到修复,我正在寻找的答案可能会在返回的jackson-core-2.5.4.jar
中找到。
ResolveReport
我在object PoisonIvy extends App {
import java.net.URL
import java.nio.file.{Path, Paths}
import org.apache.commons.io.FileUtils
import org.apache.ivy.Ivy
import org.apache.ivy.core.report.ResolveReport
import org.apache.ivy.core.resolve.ResolveOptions
import scala.collection.JavaConverters._
val confs = Array("default")
val resolveOptions = new ResolveOptions()
.setDownload(false)
.setTransitive(true)
.setConfs(confs)
val ivy: Ivy = Ivy.newInstance()
val ivyHome: Path = Paths.get(sys.props.getOrElse("ivy.home", sys.props("user.home") + "/.ivy2"))
FileUtils.listFiles(ivyHome.toFile, Array("jar"), true).asScala.find { file =>
file.getName == "jackson-core-2.5.4.jar"
}.foreach { file =>
val url: URL = file.toURI.toURL
// [Fatal Error] jackson-core-2.5.4.jar:1:1: Content is not allowed in prolog.
val resolveReport2: ResolveReport = ivy.getResolveEngine.resolve(url)
println(resolveReport2)
// [Fatal Error] jackson-core-2.5.4.jar:1:1: Content is not allowed in prolog.
val resolveReport1: ResolveReport = ivy.resolve(url, resolveOptions)
println(resolveReport1)
}
}
中使用了这些依赖项:
build.sbt
我在GitHub上发起了一个SBT项目with this code来玩。