SBT: Access to subproject managed resources?

In the SBT plugin, I am trying to access the managed resources of the 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 am working in an SBT plugin defined in plugins.sbt.

Now I need to use the resource files from the subproject (widgets) while compiling the parent project (demo).

So far the closest I've come to is the buildDependencies settings key, but I only get ProjectRef objects and the only information is the build base and project id. I couldn't find a way to get to this project resource directory.

+4


source to share


2 answers


Unfortunately, I don't think this is possible. I tried something similar but found the following in the documentation:

Note. At run time, all plugins for all assemblies are loaded into a separate parent class loader for the assembly classloaders. This means plugins will not see classes or resources from assembly definitions



See: SBT Plugins

0


source


I'm not familiar with writing plugins, but at least in yours build.sbt

you can define a resource file .

Or again in build.sbt

you can create a "shared" project that is referenced by others , for example:

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

      

Then other code (like Task) can refer to it like this:



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 can run this one or link to this directory

Hopefully there is a direct way to implement one of these plugin versus build solutions?

0


source







All Articles