Re: [sbt] package task with arguments to create a file

55 views
Skip to first unread message

Havoc Pennington

unread,
May 20, 2013, 8:36:15 AM5/20/13
to simple-build-tool
Hi,

Without working this out entirely myself, I can give you some pointers
in the right direction maybe. Assuming 0.12.x

First be sure to know the basics from Getting Started
http://www.scala-sbt.org/release/docs/index.html from Welcome down
through Custom Settings and Tasks.

Second I think you will need a custom task, like your my-package, and
to take parameters it needs to be an InputTask. with a parser for the
parameters. See
http://www.scala-sbt.org/release/docs/Extending/Input-Tasks.html

Third to implement your custom task, I'm not sure of the very best
approach. The problem is that if you depend on the existing "package"
then it would run before your task, so you couldn't modify its
settings such as the file it outputs. However... the simplest hack
might be to depend on "package" (which will give you the File it
creates) and then just copy or rename the jar you get based on your
InputTask parameters. The Getting Started stuff is hopefully clear on
how to do this dependency.

Hope that gets you started... maybe someone else will have a better approach.
Havoc



On Sun, May 19, 2013 at 10:14 AM, Matthieu Taggiasco <ma...@taggiasco.ch> wrote:
> Hi all,
>
> I'm trying to use the package task in order to package my application.
> However some properties are specific, and I would like to put them as
> arguments of the package task (or another one maybe?) in order to add a new
> resource file according to their values.
>
> I read the documentation of SBT, but I'm a bit lost with all the
> possibilities it offers. Should I implement a new task on which the package
> task would depend on ? Or should I do something else ?
>
> A simple example would be :
> package "first parameter for filename" "second parameter as file content"
>
> Or if needed :
> my-package "first parameter for filename" "second parameter as file content"
>
> I put the quotes just as examples, I don't if I have to put them somewhere
> else (I think so, as I read the doc).
>
> May anyone help ?
>
> Thanks,
> Matt
>
> --
> You received this message because you are subscribed to the Google Groups
> "simple-build-tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to simple-build-t...@googlegroups.com.
> To post to this group, send email to simple-b...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Josh Suereth

unread,
May 20, 2013, 9:11:43 AM5/20/13
to simple-b...@googlegroups.com
Just a note, you can depend on "mappings in (packageBin,Compile)", and this will give you a Seq[(File, String)]  (or a sequence of files and filenames ot place in a zip), which you could filter/expand based on your input.

Matthieu Taggiasco

unread,
May 20, 2013, 3:21:50 PM5/20/13
to simple-b...@googlegroups.com
Hi,

Thanks for both answers. I'll have a look at the links you provided. However that's not just the name of the jar file I want to rename. I need to create a ressource file in the jar.
Then I'll have a look on the suggestion of the dependency on the mappings, even if I'm not sure yet to understand what it really means. 

I'll put some info as soon as I get something working or almost working. 
Matt

Matthieu Taggiasco

unread,
May 22, 2013, 2:32:46 PM5/22/13
to simple-b...@googlegroups.com
Hi,

I finally managed to create the Input Task.

But I don't really get how to depend on "mappings in (packageBin,Compile)". For the moment, my Input Task is defined with an InputKey[Unit]. Should it be something else ?
How do I write the dependency ?

Thanks !!
Matt



Le lundi 20 mai 2013 15:11:43 UTC+2, Fluffy a écrit :
Reply all
Reply to author
Forward
0 new messages