3

I have a simple Scala application built using spray.io. I am using Scala 2.11.2 and SBT 0.13.0. All of my dependencies are listed here:

libraryDependencies ++= Seq(
  "com.typesafe.akka"  %% "akka-actor"          % "2.3.6",
  "com.typesafe.akka"  %% "akka-slf4j"          % "2.3.6",
  "io.spray"            % "spray-can_2.11"      % "1.3.2",
  "io.spray"            % "spray-routing_2.11"  % "1.3.2",
  "io.spray"            % "spray-json_2.11"     % "1.3.1"
)

libraryDependencies += "org.mongodb" %% "casbah" % "2.7.2"

libraryDependencies += "com.stormpath.sdk" % "stormpath-sdk-api" % "1.0.RC4.2"

libraryDependencies += "com.stormpath.sdk" % "stormpath-sdk-httpclient" % "1.0.RC4.2"

While building and running it locally everything is fine but when i try to push / deploy it to PaaS platforms like cloudControl or heroku i am getting below dependency issue:

   [info] Resolving org.apache.httpcomponents#httpclient;${httpclient.version} ...
   [warn]   module not found: org.apache.httpcomponents#httpclient;${httpclient.version}
   [warn] ==== local: tried
   [warn]   /tmp/scala_buildpack_build_dir/.sbt_home/.ivy2/local/org.apache.httpcomponents/httpclient/${httpclient.version}/ivys/ivy.xml
   [warn] ==== public: tried
   [warn]   http://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/${httpclient.version}/httpclient-${httpclient.version}.pom
   [warn] ==== spray repo: tried
   [warn]   http://repo.spray.io/org/apache/httpcomponents/httpclient/${httpclient.version}/httpclient-${httpclient.version}.pom
   [warn] ==== spray nightlies: tried
   [warn]   http://nightlies.spray.io/org/apache/httpcomponents/httpclient/${httpclient.version}/httpclient-${httpclient.version}.pom
   [warn] ==== public: tried
   [warn]   http://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/${httpclient.version}/httpclient-${httpclient.version}.pom

...

   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   [warn]   ::          UNRESOLVED DEPENDENCIES         ::
   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   [warn]   :: org.apache.httpcomponents#httpclient;${httpclient.version}: not found
   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   [warn]   ::              FAILED DOWNLOADS            ::
   [warn]   :: ^ see resolution messages for details  ^ ::
   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   [warn]   :: com.stormpath.sdk#stormpath-sdk-api;1.0.RC4.2!stormpath-sdk-api.jar
   [warn]   ::::::::::::::::::::::::::::::::::::::::::::::
   sbt.ResolveException: unresolved dependency: org.apache.httpcomponents#httpclient;${httpclient.version}: not found

...

   [error] (*:update) sbt.ResolveException: unresolved dependency: org.apache.httpcomponents#httpclient;${httpclient.version}: not found
   [error] download failed: com.stormpath.sdk#stormpath-sdk-api;1.0.RC4.2!stormpath-sdk-api.jar
   [error] Total time: 59 s, completed May 4, 2015 1:05:37 PM

Inspecting my dependencies using sbt-dependency-graph shows me that not resolved org.apache.httpcomponents:httpclient is a nested dependency of com.stormpath.sdk:stormpath-sdk-httpclient:1.0.RC4.2.

For some reason variable ${httpclient.version} is not resolved during built - but that is all I can figure it out here. Please help!!!

mkorszun
  • 4,461
  • 6
  • 28
  • 43
  • seems like you forgot an `s` before a string. look at your dependencies, and search for a: `"org.apache.httpcomponents" % "httpclient" % "${httpclient.version}"` and change it to: `s"${httpclient.version}"` – gilad hoch May 04 '15 at 15:45
  • @giladhoch but `httpclient` is a nested dependency of `com.stormpath.sdk:stormpath-sdk-httpclient:1.0.RC4.2` - i do not specify it explicitly. – mkorszun May 04 '15 at 15:51
  • yes, sorry, I saw it too late. @pedrofurla solution should work for you. also, you can use `dependencyOverrides` key instead of excluding. – gilad hoch May 04 '15 at 15:55

1 Answers1

5

I am not sure what is going on. But excluding the transitive dependency and adding it to SBT explicitily seems to fix the problem, at least the unresolved dependency problem:

libraryDependencies += "com.stormpath.sdk" % "stormpath-sdk-httpclient" % "1.0.RC4.2" exclude("org.apache.httpcomponents","httpclient")

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.2.2"

But keep in mind that we don't really know which version of apache's httpclient stormpath-sdk-httpclient used in its compilation, so you might run into runtime classpath/linking related exceptions. If that happens I recommend asking the developers of stormpath-sdk-httpclient.

EDIT:

you can see the version they used at: https://github.com/stormpath/stormpath-sdk-java/blob/master/pom.xml#L98

Community
  • 1
  • 1
pedrofurla
  • 12,763
  • 1
  • 38
  • 49
  • 1
    This is the correct answer - I have no idea why you have to exclude a transitive dependency only to add it back in again. Must be an `sbt` issue. – Les Hazlewood May 05 '15 at 01:19
  • @Hazlewood it's not a "sbt issue". It seems that the artifact in question was published with malformed pom.xml, not specifying the version correctly. (To be more accurate, it was specified in a parent pom, but the actual published pom did not refrenced it) – gilad hoch May 14 '15 at 09:29
  • True. I did't bother mentioning that because it'd not help the solution. – pedrofurla May 17 '15 at 19:31