sbt [0.10]: Adding dependencies to default tasks

143 views
Skip to first unread message

philcali

unread,
Jun 10, 2011, 5:08:38 PM6/10/11
to simple-build-tool
I apologize in advance if this question was answered already...

Is there a way in sbt 0.10 that I can ensure a custom task will be run
as a dependency to a default task? For example:

How would I add myTask as a dependency to copyResources? Below seems
like a natural choice:

copyResources <<= copyResources dependsOn myTask

But this produces the following error: sbt.Init$Uninitialized:
Reference to uninitialized setting.

Thanks!

-- Philip Cali

Keith Irwin

unread,
Jun 10, 2011, 8:56:44 PM6/10/11
to simple-b...@googlegroups.com
Sometimes you have to use the Scope declarations when you get the uninitialized error. For instance:

(someTask in Compile) <<= (someTask in Compile).dependsOn(yourTask)

Something like that. But in a lot of cases, you can just add to existing settings which contain (say) a list of resource directories, and then they get copies (or whatever) the same time the stock stuff does.

I often do this, for instance:

  cleanFiles <<= (cleanFiles, baseDirectory) {
    (files, basedir) =>
      files ++ Seq(new File(basedir, "/path/to/extra/stuff"))
  }

It's all confusing at first, IMHO. You can use inspect to find all these settings, the dependencies part of the output from inspect to trace where the settings might come from, and then just flail.

Keith

Mark Harrah

unread,
Jun 10, 2011, 9:09:00 PM6/10/11
to simple-b...@googlegroups.com

The specific problem here is not specifying the scope:

copyResources in Compile <<= copyResources in Compile dependsOn myTask

There may be a better place to hook in, however. For example, if you are generating resources, see the source/resource generation section here:

https://github.com/harrah/xsbt/wiki/Common-Tasks

-Mark

> Thanks!
>
> -- Philip Cali
>

philcali

unread,
Jun 10, 2011, 10:04:42 PM6/10/11
to simple-build-tool
You and Keith answered my question beautifully. Thank you guys for the
quick response!

On Jun 10, 8:09 pm, Mark Harrah <dmhar...@gmail.com> wrote:
> On Fri, 10 Jun 2011 14:08:38 -0700 (PDT)
>
Reply all
Reply to author
Forward
0 new messages