2016-11-15 74 views
0

試圖運行我的項目時出現此錯誤。如何解決類型安全配置上的NoSuchMethodError?

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

試圖清除ivy2緩存沒有成功。 這是我的構建SBT看起來像:

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 

任何想法如何解決呢?

UPDATE: java.class.path顯示

/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

+0

您可能還希望共享的代碼包含這個'getDuration'呼叫的線路。 – mfirry

+0

@mfirry沒有這樣的行,即沒有明確地調用這個方法的代碼。然而其他庫可能會調用如scalatest/akka等' – igx

+0

我會有興趣看到更多的信息/ typesafe配置文件/是完整的構建文件? – Barry

回答

1

這聽起來像一個classpath的問題。您可能正在使用調用(使用)Typesafe Config的庫,但路徑中的Typesafe Config版本低於1.3.0。 Typesafe Config 1.3.0中引入了未找到的方法。要查看運行時類路徑,確保這些陳述所執行的第一批(您的應用崩潰之前即):

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

一旦你發現你沒有類型安全配置1.3.0,其添加爲顯式依賴。

+0

補充說,明確的依賴解決了這個問題 - 謝謝! – igx

+0

你知道我怎樣才能解決它在常春藤回購? – igx

+0

如果您將它添加到您的依賴項中,您的構建系統(sbt?)應該將其下載到您的常春藤回購站。 (例如,sbt使用Ivy來進行依賴關係解析。)這是否發生? – radumanolescu

1

添加類型安全1.3.1的依賴可能會幫助,將其添加爲您的依賴性SEQ()的一部分:

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