如何在SBT中的项目之间共享资源 [英] How to share resources between projects in SBT

查看:154
本文介绍了如何在SBT中的项目之间共享资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在工作的项目是 Lift 框架上的webapp.我们也在使用 xsbt网络插件.有一个核心"项目,其中包含绝大多数功能.我当前的目标是创建两个分发"项目,这些项目将不同的类路径资源集添加到核心"项目.问题是我要么1)无法运行分发"项目,要么2)使它们运行,但是所需的资源似乎不存在.

The project I'm working on at work is a webapp on the Lift Framework. We're using xsbt web plugin as well. There's a "core" project, which contains the vast majority of the functionality; my current goal is to create two "distribution" projects that add a different set of classpath resources to the "core" project. The problem is that I either 1) can't get the "distribution" projects to run, or 2) Get them to run, but the required resource doesn't seem to be there.

我尝试过的事情

这是我的project/Build.scala的精简版:

lazy val core = Project("Core", file("core"))
  .settings( /*some dependencies, resolvers, webSettings */ )

lazy val app1 = Project("App1", file("app1"))
  .aggregate(core)
  .settings( /*the same settings as core */ )

lazy val app2 = Project("App2", file("app2"))
  .aggregate(core)
  .settings( /*the same settings as core*/ )

然后在app1app2的目录结构中,我在src/main/resources/aFileINeed处有一个文件.核心应用程序正在使用class.getResource方法从类路径加载文件.

Then in the directory structure for both app1 and app2, I have a file at src/main/resources/aFileINeed. The core application is using the class.getResource approach to load the file from the classpath.

问题

如果我尝试使用container:start运行某个分发项目,则它不会在类路径中检测到所需的文件.此外,它声称src/main/webapp不是现有目录(该文件夹包含在核心项目中,因为xsbt Web插件需要该文件夹).

If I try to run one of the distribution projects, using container:start, it does not detect the required file in the classpath. Also, it claims that src/main/webapp is not an existing directory (that folder is included in the core project, as it is required by the xsbt web plugin).

我如何才能使这些项目合并"它们的资源?我希望在Build.scala项目定义中使用aggregatedependsOn可以为我自己处理,但是显然没有.

How can I get these projects to "merge" their resources? I expected that using aggregate or dependsOn in the Build.scala project definition would handle that for me, but it apparently doesn't.

推荐答案

这就是我正在做的.我在项目的根目录中创建一个全局资源"目录,然后创建以下变量:

This is what I'm doing. I create a global 'resources' directory in the root of the project, and then the following variable:

    lazy val globalResources = file("resources")

然后在每个项目的设置中:

And then in every project's settings:

    unmanagedResourceDirectories in Runtime += globalResources 

对于使用xsbt-web-plugin或其他导入它的库的项目,您将不得不使用更强大的

For projects that use the xsbt-web-plugin or some other library that imports it you'll have to use the stronger

    unmanagedResourceDirectories in Compile += globalResources

请注意,使用此解决方案时,如果您两次定义相同的文件,则您的项目可能会具有多个资源目录和AFAIK.compile:copy-resources会让您很生气.

Beware that using this solution your projects will potentially have muliple resource directories and AFAIK if you define the same file twice compile:copy-resources is going to be angry at you.

这篇关于如何在SBT中的项目之间共享资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆