How do I get SBT staging directory at build time?にある情報に基づいて、私はうまくいくソリューションを考え出すことができました。あなたは、タスク(またはコマンド)を定義する必要があります(SBT 0.13.13)
それはあなたがstaging`ディレクトリを取得することができますようにState
は、提供されています:
lazy val printRepos = taskKey[Unit]("Print path to dependencies that are hosted in git repositories.")
printRepos := {
import sbt.BuildPaths._
val s = state.value
val staging = getStagingDirectory(s, getGlobalBase(s))
// root is a reference to your top-level project, which has
// git-hosted dependencies.
val repos = gitRepos(staging, root.dependencies)
println("${repos.mkString(",")}")
}
gitRepos
方法は、(下記)かかりステージングディレクトリと依存関係、git reposのように見えるものをフィルタリングし、プロジェクト、元のURI、ソースを保持するローカルパスを組み合わせた一連のタプルを返します。
ソースをローカルに格納するために使用される実際のディレクトリは、Resolvers.git
によって返されます。これには、ResolveInfo
オブジェクトが必要です。順番に再利用Resolvers.gitに不正なResolveInfo
を構築し、私はあなたがその周りを得ることができるとは思わないgitRepos
:
def gitRepos(staging: File, cps: Seq[ClasspathDep[ProjectReference]]): Seq[(ProjectReference, URI, File)] = {
import sbt.BuildLoader._
import sbt.RichURI._
val x = cps.flatMap(cp => Reference.uri(cp.project).map(uri => (cp.project, uri)))
x.flatMap({ case (project, uri) => {
// Stolen from sbt.RetrieveUnit
if(uri.getScheme == "git" || uri.withoutMarkerScheme.getPath.endsWith(".git")) {
val y = Resolvers.git(new ResolveInfo(uri, staging, null, null))
y.map(path => (project, uri, path()))
}
else
None
}})
}
getRepos
がResolvers.git
を再使用しているので、printRepos
は常にsbt
という正確なディレクトリを印刷しますプロジェクト参照を格納するために使用します。