Getting Settings and Arguments with SBTs InputTask

I've written an SBT plugin that allows SBT users to define arbitrary tasks in their project that can be run (with full classpath and dependencies loaded) from SBT itself.

The body of the functionality looks like this

  def installTask(taskName: String, taskDescription: String = "") = {
    TaskKey[Unit](taskName, taskDescription) <<= (dependencyClasspath in Runtime)
      .map(loadTask(_, "tasks", taskName.capitalize))

  private def loadTask(dependencies: Keys.Classpath, taskPackage:String, className: String) = {
    val dependenciesUrls =
    val classLoader = new URLClassLoader(dependenciesUrls, null)
    val taskClass = s"$taskPackage.$className"

So people can, in their SBT file do this

import SbtTasks._


And when the call sbt seedDB the tasks.SeedDB will be executed in the application context.

Now the problem - I need to do this but accept arguments. I've got as far as understanding how to accept arguments

  def installTaskWithArgs(taskName: String, taskDescription: String = "") = {
    val input = InputKey[Unit](taskName, taskDescription)

    input := {
      val args: Seq[String] = Def.spaceDelimited("<arg>").parsed

But I can't work out how to, in this context access the values of my dependencyClasspath within the InputTask

  val dc = (dependencyClasspath in Runtime)

I also tried Commands but they seemed a bit more troublesome and all content appears to promote InputTasks over Commands anyway.

So - how do I accept arguments in a task while also getting access to the dependencyClasspath?

NB: Code has been elided for brevity please excuse any obvious exclusions


I think inputTaskDyn is your friend here:

input :=
  Def.inputTaskDyn {
    val args = Def.spaceDelimited("<arg>").parsed
    val dc = (dependencyClasspath in Runtime).value

for some background and links to further reading, see

Need Your Help

jQuery.ajax() with window.onbeforeunload not sending data

javascript php ajax jquery

Im trying to store data of how many clicks and the amount of time a visitor spends on the site

Perl Data::Dumper numeric sort on first level key of HoH


I have a HoH data structure. The outer level hash's keys are numeric - so I'd like to Dump the HoH numerically sorted by the first hash key (don't care about the order on the inner hash). I've been