Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT: Access managed resources of a subproject?

Tags:

plugins

scala

sbt

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

Here is the build file:

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)

}

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).

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.

like image 790
erwan Avatar asked Feb 06 '13 09:02

erwan


1 Answers

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

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))
    )
  )

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?

like image 117
ecoe Avatar answered Nov 14 '22 12:11

ecoe