-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change sourceDirectory and/or stageDirectory in Universal from Settings to Tasks #34
Comments
So, in general, you shouldn't be doing anything like that with "sourceDirectory". These are default settings. The actual meat of the plugin is configured with This is actually a common error in sbt: Trying to push your tasks into the wrong point. In sbt, the build takes a more functional flow. For every "settings" that we want users to touch, there's usually an associated task that does the actual work, e.g. "sources" task vs. "sourceDirectory" task. We take a similar approach here. You should be able to get what you want without any changes. Let me know if you have issues. In particular (in sbt 0.13 syntax): val downloadZipUrl = settingKey[URI]("Where I download the zip file from")
val downloadZipLocation = settingKey[File]("Where I download the zip file to ")
val downloadZipFile = taskKey[File]("Download the zip file")
val zipFileMappings = taskKey[Mappings]("Contents of the zip file I want to package")
downloadZipUrl := new java.net.URI("My awesome location")
downloadZipLocation := target.value / "my-zip-exploded"
downloadZipFile := {
val tmp = java.io.File.createTempFile("zip", "file")
IO.download(downloadZipUrl.value, tmp)
IO.unzip(tmp, downloadZipLocation.value)
}
zipFileMappings := {
val location: File = downloadZipLocation.value
// Here's the Path API crazyness
val finder: PathFinder = (location.*** --- location)
// If you've never seen the `x` method before, it takes the path finder (file finder) and
// gives you a mapping from java.io.File -> some String. In this case, `relativeTo` gives
// use the relative file name to "location" (the zip root).
val mappings: Seq[(File, String)] = finder x relativeTo(location)
}
// Here we add our zip file to the universal packaging
mappings in Universal ++= zipFileMappings.value Hope that helps! |
Thanks for your suggestions, I'll try it out ! |
NO problem! I used to the same thing myself (try to use settings as tasks and hook the wrong entry points). I'd say it's the second biggest hurdle to overcome, just trying to make sure you have a smoother path to success :) |
I tried your solution, and it worked perfectly :) |
Some context first :
In my SBT build, I need to repackage a bundle, previously built with sbt-native-packager by another build and published in my Ivy repo, in order to add some files in it.
This means that I need to :
The first two steps have to be done in a task, as I can't expect that the bundle has been already fetched when the project loads.
However, this means that
sourceDirectory
orstagingDirectory
in Universal must be tasks, as settings can't depend on tasks...Would it be possible to change those (or one of those) two settings to tasks ? Looking at the code of
UniversalPlugin
, it seems that the impact would be minimal.In my case, changing
stagingDirectory
to a task would be sufficient : the structure is already there, so the unzipped bundle would be a perfectly fine staging directory.I can submit a PR if you like :)
The text was updated successfully, but these errors were encountered: