4

I have an external lib directory with jars. I need these included in my classpath in order to compile and test my project but I do not want to include them in the distributed zip file that is generated via universal:packageBin (in the sbt-native-packager) (or dist if you're using the playframework.

I attempted to do this by using the provided scope as follows:

unmanagedBase in Provided := new java.io.File("/external/lib")

But this doesn't seem to work as advertised - the jars don't seem to get included in the Compile scope.

I am using sbt 0.13.1.

ishaaq
  • 6,329
  • 3
  • 16
  • 28
  • Try `unmanageBase in packageBin := file("/external/lib")` – laughedelic Mar 24 '14 at 16:48
  • unfortunately, @laughedelic, that removes the deps from Compile scope - I still need them there :( – ishaaq Mar 24 '14 at 20:40
  • Doesn't `unmanageBase in Compile := file("/external/lib")` help with both `Compile` scope and `packageBin` task? If no, you can just set both separately. – laughedelic Mar 25 '14 at 09:16
  • sorry, you misunderstand - I want the umanaged jars in compile (and test) but I *don't* want them included in the binary distribution. I am basically trying to replicate what Provided scope does in maven. – ishaaq Mar 25 '14 at 13:47
  • Does anyone know how to do this? – Dimitry Mar 31 '14 at 13:28

2 Answers2

3

This works (thanks @jacek-laskowski for the improvements to my answer):

mappings in Universal :=  (mappings in Universal).value.filter { case(jar, _) => jar.getParentFile != unmanagedBase.value }

But, it still feels like a kludge, I would much prefer it if sbt (and the sbt-native-packager) would properly support the Provided scope as this scenario is exactly what it is meant for.

ishaaq
  • 6,329
  • 3
  • 16
  • 28
1

I'd propose the following solution:

mappings in Universal := (mappings in Universal).value filter { case (jar, path) => 
  jar.getParentFile != (unmanagedBase in Compile).value
}

It duplicates mappings in Universal that could be avoided with ~=, but then no .value macro support offered.

I think the solution is however type-safe since it uses the value of unmanagedBase in Compile setting that's java.io.File (not java.lang.String which is prone to typos).

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420