1

I'm getting this error when trying to run my project.

Exception in thread "main" java.lang.NoSuchMethodError: com.typesafe.config.Config.getDuration(Ljava/lang/String;)Ljava/time/Duration;

tried to clear ivy2 cache with no success . this is how my build sbt looks like :

scalaVersion  := "2.11.7"
scalacOptions := Seq("-unchecked", "-feature", "-deprecation", "-encoding", "utf8")

resolvers ++= Seq(
  Resolver.sonatypeRepo("releases"),
  Resolver.sonatypeRepo("snapshots"),
  Resolver.bintrayRepo("websudos", "oss-releases"),
  "spray repo"                       at "http://repo.spray.io",
  "Typesafe repository snapshots"    at "http://repo.typesafe.com/typesafe/snapshots/",
  "Typesafe repository releases"     at "http://repo.typesafe.com/typesafe/releases/",
  "Sonatype repo"                    at "https://oss.sonatype.org/content/groups/scala-tools/",
  "Sonatype releases"                at "https://oss.sonatype.org/content/repositories/releases",
  "Sonatype snapshots"               at "https://oss.sonatype.org/content/repositories/snapshots",
  "Sonatype staging"                 at "http://oss.sonatype.org/content/repositories/staging",
  "Sonatype"                         at "https://oss.sonatype.org/content/groups/public/",
  "Java.net Maven2 Repository"       at "http://download.java.net/maven/2/",
  "Twitter Repository"               at "http://maven.twttr.com"
)

libraryDependencies ++= {
  val phantomV         = "1.29.5"
  val scalaTestV       = "3.0.0"
  val elastic4sV       = "2.4.0"
  val akkaStreamVersion = "2.4.2"
  val akkaVersion = "2.3.11"
  Seq(
    "com.websudos"            %%  "phantom-dsl"                       % phantomV,
    "com.websudos"            %%  "phantom-reactivestreams"           % phantomV,
    "com.websudos"            %%  "util-testing"                      % "0.13.0"    % "test, provided",
    "com.typesafe.akka"       %% "akka-actor"                         % akkaVersion,
    "com.typesafe.akka"       %% "akka-http-spray-json-experimental"  % akkaStreamVersion,
    "com.typesafe.akka"       %%  "akka-http-core"                    % akkaStreamVersion,
    "com.typesafe.akka"       %% "akka-http-experimental"             % akkaStreamVersion,
    "com.typesafe.akka"       %% "akka-http-testkit"                  % akkaStreamVersion,
    "org.scalatest"           %% "scalatest"                          % scalaTestV % "test",
    "com.typesafe.akka"       %% "akka-testkit"                       % akkaVersion % "test",
    "com.typesafe.play"       %%  "play-streams-experimental"         % "2.4.6",
    "com.sksamuel.elastic4s"  %% "elastic4s-core"                     % elastic4sV,
    "com.sksamuel.elastic4s"  %% "elastic4s-streams"                  % elastic4sV
  )
}
lazy val root = project.in(file(".")).configs(IntegrationTest)
Defaults.itSettings

initialCommands := """|import akka.actor._
                      |import akka.pattern._
                      |import akka.util._
                      |import scala.concurrent._
                      |import scala.concurrent.duration._""".stripMargin
fork in run := true

any idea how to solve it ?

UPDATE: java.class.path shows

/Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jps-builders.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/trove4j.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/scala-library.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/scala-nailgun-runner.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/compiler-settings.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/nailgun.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/sbt-interface.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/incremental-compiler.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/scala-jps-plugin.jar:/Users/avi/Library/Application Support/IntelliJIdea2016.2/Scala/lib/jps/dotty-interfaces.jar

igx
  • 4,101
  • 11
  • 43
  • 88
  • You may also want to share the line of code that contains this `getDuration` call. – mfirry Nov 15 '16 at 13:26
  • @mfirry There is no such line, i.e no where in the code I call this method explicitly. however other libraries might be calling is such as scalatest/ akka etc' – igx Nov 15 '16 at 13:32
  • I would be interested in seeing more information / typesafe config files/ is that the full build file? – Barry Nov 15 '16 at 13:39
  • Which version of Typesafe config JAR is in the classpath? `java.time.Duration getDuration(java.lang.String path)` was added in 1.3.0. Maybe you are using an earlier version of the library. – radumanolescu Nov 15 '16 at 13:46
  • @user2128014 thanks, how can I see that ? – igx Nov 15 '16 at 13:58
  • It sounds like the code that calls `getDuration` is in a library that is called from a library that is called from ... the OP's code - so it sounds like a classpath problem, where the JAR in the classpath is less than 1.3.0. For instance, in my current Ivy repo I have `repo/com.typesafe/config/bundles/config-1.3.0.jar` – radumanolescu Nov 15 '16 at 13:58
  • @igx In you app, add this as the first thing that is executed: `val cp = System.getProperty("java.class.path")`; println(cp). Are you on Windows or Linux? – radumanolescu Nov 15 '16 at 14:00
  • @user2128014 in my ivy2 repo com.typesafe/config/bundles/config-1.2.0.jar and config.1.2.1.jar – igx Nov 15 '16 at 14:06
  • @user2128014 as for the java.class.path - I have updated in my question above – igx Nov 15 '16 at 14:08

2 Answers2

3

Adding TypeSafe 1.3.1 as dependency might help, add it as part of your Seq() of dependencies:

"com.typesafe" % "config" % "1.3.1"
2

It sounds like a classpath problem. You may be using a library that calls (uses) Typesafe Config, but the version of Typesafe Config in your path is less than 1.3.0. The method that is not found was introduced in Typesafe Config 1.3.0. To see your runtime classpath, make sure these statements are the first ones that are executed (i.e. before your app crashes):

val cp = System.getProperty("java.class.path")
val sep = System.getProperty("path.separator")
cp.split(sep).foreach(println)

Once you see that you do not have Typesafe Config 1.3.0, add it as an explicit dependency.

radumanolescu
  • 4,059
  • 2
  • 31
  • 44