alifirat
alifirat

Reputation: 2937

SBT run fails when I'm launching it

I have a little problem when I'm running the command sbt run :

$ sbt run 
java.lang.NoSuchMethodError: com.typesafe.config.ConfigFactory.defaultApplication(Lcom/typesafe/config/ConfigParseOptions;)Lcom/typesafe/config/Config;
    at play.api.Configuration$$anonfun$3.apply(Configuration.scala:75)
    at play.api.Configuration$$anonfun$3.apply(Configuration.scala:71)
    at scala.Option.getOrElse(Option.scala:121)
    at play.api.Configuration$.load(Configuration.scala:71)
    at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:203)
    at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:61)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:60)
    at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:50)
    at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at play.runsupport.Reloader$.startDevMode(Reloader.scala:207)
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.devModeServer$lzycompute$1(PlayRun.scala:73)
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.play$sbt$run$PlayRun$$anonfun$$anonfun$$anonfun$$devModeServer$1(PlayRun.scala:73)
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:99)
    at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:52)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)

Most of errors that I met with sbt have one issue when I google it but for this kind of error, no idea how to fix that.

My file build.sbt:

import play.routes.compiler.InjectedRoutesGenerator
import play.sbt.PlayScala


version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  cache,
  ws,
  filters,
  "com.typesafe" % "config" % "1.0.0",
  "org.reactivemongo" %% "play2-reactivemongo" % "0.11.7.play24",
  "com.amazonaws" % "aws-java-sdk" % "1.10.12",
  "org.webjars" %% "webjars-play" % "2.4.0-1",
  "org.webjars" % "bootstrap" % "3.3.5",
  "org.webjars" % "angularjs" % "1.4.7",
  "org.webjars" % "angular-ui-bootstrap" % "0.14.3",
  "org.webjars" % "angular-ui-router" % "0.2.15"
)

resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/"

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

Anybody see one issue for this problem ?

Update with application.conf :

# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
#
# This must be changed for production, but we recommend not changing it in this file.
#
# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
play.crypto.secret = "changeme"

# The application languages
# ~~~~~
play.i18n.langs = [ "en" ]

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `my.application.Router`,
# you may need to define a router file `conf/my.application.routes`.
# Default to Routes in the root package (and conf/routes)
# play.http.router = my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
# db.default.driver=org.h2.Driver
# db.default.url="jdbc:h2:mem:play"
# db.default.username=sa
# db.default.password=""

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# play.evolutions.enabled=false

# You can disable evolutions for a specific datasource if necessary
# play.evolutions.db.default.enabled=false

play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"

project/plugins.sbt:

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")

Upvotes: 2

Views: 1192

Answers (3)

juanmirocks
juanmirocks

Reputation: 6239

The same error can happen if you put some play libraries into a provided environment classpath (as with an assembled fat jar). For example, Flink 1.3.2 has an older com.typesafe.config library, not compatible with Play 2.5 or further.

The way to solve is this is by shading the libraries as explained in sbt-assembly.

Upvotes: 0

alifirat
alifirat

Reputation: 2937

For the people meeting this problem, The way to solve it was to put the config-1.3.0.jar into the lib folder.

Upvotes: 1

vvg
vvg

Reputation: 6385

Update "com.typesafe" % "config" % "1.0.0", to 1.3.0

According to github, missed method appears in 1.3.0 version of ConfigFactory

https://github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/ConfigFactory.java

 * @since 1.3.0
 *
 * @param options the options
 * @return the default application configuration
 */
public static Config defaultApplication(ConfigParseOptions options) {
    return parseApplicationConfig(ensureClassLoader(options, "defaultApplication"));
}

Upvotes: 1

Related Questions