Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SBT从外部git存储库管理XML资源(运行时需要)_Git_Scala_Resources_Sbt - Fatal编程技术网

使用SBT从外部git存储库管理XML资源(运行时需要)

使用SBT从外部git存储库管理XML资源(运行时需要),git,scala,resources,sbt,Git,Scala,Resources,Sbt,我在SBT中有一个Scala项目,在运行时它需要访问一组XML文件,我希望从git中获取这些文件,并在构建时将其放在类路径上。这些XML来自我无法控制的外部git存储库,因此我无法合并这两个Repo 我看到SBT允许您添加unmanagedResourceDirectory和managedResourceRedirectories(不确定区别是什么),这允许您指示SBT将目录添加到类路径,但我不确定如何从git repo获取目录,而不是磁盘上的实际目录。您可以使用本地克隆repo,并使用arch

我在SBT中有一个Scala项目,在运行时它需要访问一组XML文件,我希望从git中获取这些文件,并在构建时将其放在类路径上。这些XML来自我无法控制的外部git存储库,因此我无法合并这两个Repo

我看到SBT允许您添加
unmanagedResourceDirectory
managedResourceRedirectories
(不确定区别是什么),这允许您指示SBT将目录添加到类路径,但我不确定如何从git repo获取目录,而不是磁盘上的实际目录。

您可以使用本地克隆repo,并使用
archive
命令从repo中复制文件。举个例子,看看插件是如何实现的

如果不需要平台独立性,可以通过调用命令行git命令,并结合
clone
/
fetch
更新依赖项和
archive
提取文件

从本地存储库复制某些路径的代码部分:

// needed for installSource
// maybe implement some archiver to go directly to files?
org.eclipse.jgit.archive.ArchiveFormats.registerAll()

def installSource(cachedRepo: Git, paths: Seq[String], revision: ObjectId, target: File): Set[File] =
    IO.withTemporaryFile(target.getName, ".zip") { tmp =>
    val out = new BufferedOutputStream(new FileOutputStream(tmp))

    cachedRepo
        .archive()
        .setFormat("zip")
        .setTree(revision)
        .setPaths(paths :_*)
        .setOutputStream(out)
        .call()

    IO.unzip(tmp, target)
    }
在本地克隆回购协议的部分代码:

def downloadGitRepo(local: File)(repo: URI): File = {

    val clone = Git
        .cloneRepository()
        .setURI(repo.toString)
        .setDirectory(local)
        .setBare(true)
        .call()

    assert(local.exists())

    local
}

谢谢你的回答!今天晚些时候我将尝试此功能,如果有效,mark将接受:-)