SBT:访问子项目的托管资源? [英] SBT: Access managed resources of a subproject?

查看:89
本文介绍了SBT:访问子项目的托管资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SBT插件中,我试图访问子项目的托管资源.

In an SBT Plugin, I'm trying to access to managed resources of subprojects.

这是构建文件:

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {
  val appName         = "demo"
  val appVersion      = "1.0-SNAPSHOT"
  val appDependencies = Seq(
    "org.jruby" % "jruby-complete" % "1.7.1"
  )

  val widgets = play.Project("widgets", appVersion, appDependencies, path = file("widgets"))
  val main = play.Project(appName, appVersion, appDependencies, path = file("demo"))
    .dependsOn(widgets)

}

我正在使用plugins.sbt中定义的SBT插件.

I'm working in an SBT plugin defined in plugins.sbt.

现在,在父项目(演示)的编译过程中,我需要使用子项目(小工具)中的资源文件.

Now, I need to use resources files from the subproject (widgets) during compilation of the parent project (demo).

到目前为止,我最接近的是buildDependencies设置键-但是我仅获得ProjectRef对象,唯一的信息是构建基础和项目ID.我找不到找到该项目资源目录的方法.

So far the closest I've got to is the buildDependencies settings key - but I'm only getting ProjectRef objects, and the only information is the build base and the project id. I couldn't find a way to get to that project's resources directory.

推荐答案

我不熟悉编写插件,但是至少在您的build.sbt中,您可以

I'm not familiar with writing plugins, but at least in your build.sbt you can define the resource file.

或者,再次在build.sbt中,您可以创建其他人引用的公共"项目,例如:

Or, again in the build.sbt you can create a "common" project that others reference, like:

lazy val common = (project in file("common"))
  .settings(
    Seq(
      includeFilter in unmanagedResources := new SimpleFileFilter(_.getCanonicalPath.startsWith((sourceDirectory.value / "main" / "resources").getCanonicalPath))
    )
  )

然后其他代码(例如Task)可以像这样引用:

Then other code (e.g. a Task) could reference this like:

lazy val doSomething = taskKey[Seq[File]]("Does something useful")
lazy val doSomethingSetting = doIt := {

  val resourceDir = (resourceDirectory in common in Compile).value
  println(resourceDir)

}

因此您的其他项目可以运行此目录,也可以引用该目录

So your other projects could run this or reference that directory

希望有一种简单的方法可以为插件与构建实现其中一种解决方案?

Hopefully there's a straight forward way to implement one of those solutions for a plugin vs a build?

这篇关于SBT:访问子项目的托管资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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