Apache httpcomponents Error downloading / librarymanagement.ResolveException

Hi, I am very new to scala, I was trying to use the apache httpcomponents, and faced some errors while compiling.

[warn] 	Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading org.apache.httpcomponents.client5:httpclient5-fluent_3:5.1.
[error]   Not found
[error]   Not found
[error]   not found: /Users/.ivy2/localorg.apache.httpcomponents.client5/httpclient5-fluent_3/5.1.3/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/apache/httpcomponents/client5/httpclient5-fluent_3/5.1.3/httpclient5-fluent_3-5.1.3.pom
[error] 	at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:345)
[error] 	at lmcoursier.CoursierDependencyResolution.$anonfun$update$38(CoursierDependencyResolution.scala:314)
[error] 	at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] 	at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:314)
[error] 	at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] 	at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:59)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:133)
[error] 	at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:73)
[error] 	at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$20(LibraryManagement.scala:146)
|[error] |at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:73)|
|---|---|
|[error] |at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$20(LibraryManagement.scala:146)|
|[error] |at scala.util.control.Exception$Catch.apply(Exception.scala:228)|
|[error] |at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:146)|
|[error] |at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:127)|
|[error] |at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:219)|
|[error] |at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:160)|
|[error] |at sbt.Classpaths$.$anonfun$updateTask0$1(Defaults.scala:3688)|
|[error] |at scala.Function1.$anonfun$compose$1(Function1.scala:49)|
|[error] |at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)|
|[error] |at sbt.std.Transform$$anon$4.work(Transform.scala:68)|
|[error] |at sbt.Execute.$anonfun$submit$2(Execute.scala:282)|
|[error] |at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)|
|[error] |at sbt.Execute.work(Execute.scala:291)|
|[error] |at sbt.Execute.$anonfun$submit$1(Execute.scala:282)|
|[error] |at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)|
|[error] |at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)|
|[error] |at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)|
|[error] |at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)|
|[error] |at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)|
[error] 	at java.base/java.lang.Thread.run(Thread.java:833)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.apache.httpcomponents.client5:httpclient5-fluent_3:5.1.3
[error]   Not found
[error]   Not found
[error]   not found: /Users/.ivy2/localorg.apache.httpcomponents.client5/httpclient5-fluent_3/5.1.3/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/apache/httpcomponents/client5/httpclient5-fluent_3/5.1.3/httpclient5-fluent_3-5.1.3.pom

the link seem to include a mysterious _.
https://repo1.maven.org/maven2/org/apache/httpcomponents/client5/httpclient5-fluent_3/5.1.3/httpclient5-fluent_3-5.1.3.pom
instead of
(https://repo1.maven.org/maven2/org/apache/httpcomponents/client5/httpclient5-fluent/5.1.3/httpclient5-fluent-5.1.3.pom)
also in the ivy directory /Users/.ivy2/localorg.apache.httpcomponents.client5/httpclient5-fluent_3/5.1.3/ivys/ivy.xm

Dependencies.scala file look like this

import sbt._                                                                  
                                                                             
object Dependencies {  
**lazy** val **httpcomponents** = "org.apache.httpcomponents.client5" %% "httpclient5-fluent" % "5.1.3"
}

build file

import Dependencies._

ThisBuild / scalaVersion     := "3.1.3"
ThisBuild / version          := "5.1.3"
ThisBuild / organization     := "org.apache.httpcomponents.client5"
ThisBuild / organizationName := "apache"

lazy val root = (project in file("."))
  .settings(
    name := "scala_test03092022",
libraryDependencies += httpcomponents % Test 
}

Could someone help me /suggest where I should check first in case like this?

Thanks!

Long story short: Replace the double percentage %% in your dependency to httpclient5 with a single %.

This is special syntax for “resolve the library artifact matching my scala compiler version”, and must not be used for plain Java dependencies.

See also sbt Reference Manual — Library dependencies

2 Likes

Hi @cestLaVie worked perfectly, thanks! will study the reference manual also…:slight_smile: