How does the sbt plugin get the file path in the plugin?

I have an sbt (0.11.2) plugin that should get the path to text files inside the plugin. How should I do it? baseDirectory, sourceDirectories, etc. are installed in the project base, including the plugin, and not the base of the module itself.

I would like to provide a command to the plugin user, which extracts the default values ​​from the ruby ​​file inside the plugin, and then allows the plugin user to override these default values.

+5
source share
1 answer

Why don't you use the old old Java class method Class.getResource or Class.getResourceAsStream? For instance. eg:

object TestPlugin extends Plugin {

  override def settings = super.settings ++ Seq(
    commands += testCommand
  )

  def testCommand = Command.command("test")(action)

  def action(state: State) = {
    try {
      val in = getClass.getResourceAsStream("/test.txt")
      val text = Source.fromInputStream(in).getLines mkString System.getProperty("line.separator")
      logger(state).info(text)
      in.close()
      state
    } catch {
      case e: Exception =>
        logger(state).error(e.getMessage)
        state.fail
    }
  }
}
+1
source

All Articles