Changing the output location of package in sbt 0.10.1

1,017 views
Skip to first unread message

Raymond Barlow

unread,
Jul 24, 2011, 3:06:22 PM7/24/11
to simple-b...@googlegroups.com
Hi,

How do I change the output location of the package command in sbt 0.10.1?

Currently, package produces:
build/scala-2.8.1.final/myapp_2.8.1-0.1.jar

I would like it to produce:
build/jar/myapp.jar

In 0.7.7, I would override the package action, and call the package task with my parameters. How is it done  in 0.10.1?

Regards,
Raymond Barlow


Mark Harrah

unread,
Jul 24, 2011, 6:56:09 PM7/24/11
to simple-b...@googlegroups.com
Hi Raymond,

The setting that you want is 'artifactPath', appropriately scoped for the artifact you are interested in modifying. For example:

artifactPath in Compile in packageBin <<=
baseDirectory { base => base / "build" / "jar" / "myapp.jar" }

The 'in Compile in packageBin' part means to set it for the main binary jar. You could change Compile to Test to modify a test jar. Or, change packageBin to packageSrc or packageDoc to modify the source or api jars, respectively.

For more on modifying the default artifacts, see:

https://github.com/harrah/xsbt/wiki/Artifacts

-Mark

> Regards,
> Raymond Barlow
>

Raymond Barlow

unread,
Jul 25, 2011, 3:42:46 AM7/25/11
to simple-b...@googlegroups.com
Hi Mark,

Thank you again for the response.

That looks like what I need. I'm actually building a zip, with a custom structure. One item in that zip will be my jar. Would you recommend that I use the artefact functionality to achieve this, or a custom task? Keeping in mind that in need to build the (correctly named) jar as part of this.

Regards,
Raymond Barlow

Raymond Barlow

unread,
Jul 25, 2011, 4:33:22 AM7/25/11
to simple-b...@googlegroups.com
Hi Mark,

It looks like the Artifact functionality is not actually what I need. My custom zip basically needs to contain:

mycorrectlynamed.jar (I used to use the package task to create this)
start.sh
stop.sh
+lib
+resources

Reading the Artifact documentation, it seems that it is geared towards pushing an Ivy or Maven artifact out. I'm just trying to create zip file for my server. 

Perhaps it's just better for me to write a custom task?

/Raymond

Mark Harrah

unread,
Jul 26, 2011, 9:53:25 AM7/26/11
to simple-b...@googlegroups.com

For a custom zip task, yes you can just use IO.zip. The API documentation for IO is here:

http://harrah.github.com/xsbt/latest/api/sbt/IO$.html

'zip' takes mappings from the input File to its String path in the zip as well as the name of the output zip. There is information on helpers for constructing the mapping here:

https://github.com/harrah/xsbt/wiki/Mapping-Files

-Mark

> /Raymond
>

Nicolas Kijak

unread,
Aug 1, 2014, 1:47:16 PM8/1/14
to simple-b...@googlegroups.com
I realize this is 3 years later but it's the only thing turning up close to what I need....

How would you get the original file name for artifact while changing just the output directory?  In this example the name is being changed to myapp.jar, I don't want to change the filename, just the location for this particular artifact. 

Nick
Reply all
Reply to author
Forward
0 new messages