7

I have project that collects dependencies for an installer (sbt-install4j) using dependencyClasspath. It works most of the time, except when I have one specific dependency:

libraryDependencies += "org.bytedeco" % "javacpp" % "0.10"

"javacpp" will not be added to the dependencyClasspath. You can create a simple SBT project with only that dependency above and try show dependencyClasspath, it will print:

[info] List(Attributed(C:\Users\me\.sbt\boot\scala-2.10.4\lib\scala-library.jar))

there is no "javacpp". Any clues what may be happening? Is this an SBT bug?

Jarek
  • 1,513
  • 9
  • 16
  • 1
    Does it do that even with `classpathTypes += "maven-plugin"`? – Samuel Audet Mar 17 '15 at 04:24
  • Yes. adding `classpathTypes += "maven-plugin"` adds dependency to the classpath. Thanks for pointing this out. It gets a bit tedious in multi-module projects. For instance, module `B` depends on `A` and `A` depends on javacpp. `A` has `classpathTypes...`, module `B` will have to add `classpathTypes...` too. My original problem was with multi-module project. Your fix works there, just needs to be added to top module too. – Jarek Mar 18 '15 at 19:28
  • I wonder why we need to tell SBT to load Maven plugins explicitly? We could also work around that by splitting the artifact in two, with a Maven plugin of like 10KB, but I feel that would be confusing... – Samuel Audet Mar 19 '15 at 07:39

1 Answers1

2

sbt excludes certain packaging types from the classpaths it generates, because not all packaging types make sense to depend on. Unfortunately, it seems to do this exclusion silently - and the default value of classpathTypes isn't always what you want.

The packaging type of the dependency can be found in the dependency's pom.xml or ivy.xml (as applicable). There are two main cases:

  1. If the packaging type is actually pom, this probably means it's a parent pom and you are trying to depend on the wrong thing - look for the specific Maven module you actually want!
  2. If on the other hand, it's maven-plugin - as in this particular case - you need to add the packaging type to classpathTypes, using: classpathTypes += "maven-plugin"

Other cases are probably going to be similar to one of the above two cases.

Robin Green
  • 32,079
  • 16
  • 104
  • 187