Unable to run Play server, getting NoSuchMethodError
Error message:
[info] p.c.s.AkkaHttpServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
(Server started, use Enter to stop and go back to the console...)
[error] java.lang.NoSuchMethodError: 'scala.tools.nsc.settings.AbsSettings$AbsSetting scala.tools.nsc.Settings.bootclasspath()'
[error] at play.twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$CompilerInstance.compiler$lzycompute(TwirlCompiler.scala:503)
[error] at play.twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$CompilerInstance.compiler(TwirlCompiler.scala:481)
[error] at play.twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$PresentationCompiler$.<init>(TwirlCompiler.scala:549)
[error] at play.twirl.compiler.TwirlCompiler$TemplateAsFunctionCompiler$PresentationCompiler$.<clinit>(TwirlCompiler.scala)
Configuration
Already tried:
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.8.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") // For passing build information.
addSbtPlugin("io.github.davidmweber" % "flyway-sbt" % "7.4.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.9")
addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.13")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.10.0-RC1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
lazy val insight = (project in file("insight"))
.enablePlugins(PlayScala, TypeSafeDockerPlugin, BuildInfoPlugin, BashStartScriptPlugin)
.settings(commonSettings)
.settings(baseBuildInfoKeys)
.settings(
Global / cancelable := false,
version := insightVersion,
resolvers += "shibboleth-release" at "https://build.shibboleth.net/nexus/content/repositories/releases", //for openSAML lib
libraryDependencies ++= insightDependencies,
libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value,
// automatically import template helpers for templates
TwirlKeys.templateImports ++= Seq(
"********.utils.Environment",
"********.models._",
"controllers._",
"templateHelpers._",
"org.joda.time.DateTime"
),
// disable js asset stuff, we manage it on our own
Assets / JsEngineKeys.npmNodeModules := Nil,
TestAssets / JsEngineKeys.npmNodeModules := Nil,
// don't produce docs
Compile / doc / sources := Seq.empty,
Compile / packageDoc / publishArtifact := false,
PlayKeys.playMonitoredFiles := {
val isUsingWebpackDevServer = Option(System.getenv("WEBPACK_DEV_SERVER_PORT")).isDefined
val filesList = PlayKeys.playMonitoredFiles.value
if (isUsingWebpackDevServer) {
(filesList --- baseDirectory.value / "public").get
} else {
filesList
}
},
// run webpack when doing dist as well for staging and production
webpackDistTask := {
val exitCode =
Process("node" :: "node_modules/webpack/bin/webpack.js" :: "--progress" :: "--colors" :: Nil, baseDirectory.value) !
if (exitCode != 0) {
// webpack build has an error
throw new RuntimeException(s"Webpack build error (exit code $exitCode). Check for errors above")
}
val versionRegex = "\\.([0-9a-f]*)\\.bundle".r
val version =
versionRegex.findFirstMatchIn(IO.readLines(baseDirectory.value / "conf" / "webpack-assets.json")(0)).get.group(1)
IO.write(baseDirectory.value / "conf" / "version.conf", s"webpack.version=$version".getBytes)
},
dist := (dist dependsOn webpackDistTask).value
)
.settings(commonDockerSettings)
.settings(dockerBuildInsight)
.dependsOn(knowledge)
The class scala.tools.nsc.Settings
(the method bootclasspath) is from scala-compiler
https://mvnrepository.com/artifact/org.scala-lang/scala-compiler/2.12.13
Try to add
libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value
to your build.sbt
.
Does this change anything for you?
Actually, I managed to reproduce java.lang.NoSuchMethodError: 'scala.tools.nsc.settings.AbsSettings$AbsSetting scala.tools.nsc.Settings.bootclasspath()
even with fresh Play installation sbt new playframework/play-scala-seed.g8
(Play 2.7.9, Scala 2.12.13, jdk-17.0.5). Accessing http://localhost:9000/ leads to slightly different stack trace in my case https://gist.github.com/DmytroMitin/a36fc85966bfcf1481d7ec0b516ffc9f
The stacktrace is even closer to yours with sbt outside IntelliJ: at play.twirl.compiler...
https://gist.github.com/DmytroMitin/9f6c3982bb7bd0c715c86f4c4a61a6eb
Play 2.8.0 is the first version were we officially support Java 11. Play, its standalone modules, samples and seeds are all tested against AdoptOpenJDK 8 & 11. We continue to support Java 8 as the default version
https://www.playframework.com/documentation/2.8.19/Highlights28#Java-11-support
So Play 2.7 may not work with Java 11.
Try to upgrade to Play 2.8. The issue seems not to reproduce there.
One more option (if you'd like to stay on Play 2.7) is to downgrade sbt to 1.3.x (modify project/build.properties
).
https://github.com/sbt/sbt/issues/6400
https://www.reddit.com/r/scala/comments/pjhex0/error_javalangnosuchmethoderror/
The thing seems to be in a conflict between Play and sbt versions. More precisely, between twirl-compiler
and scala-compiler
. twirl-compiler
doesn't seem to respect patch version 2.12.x of scala-compiler
. Different patch versions 2.12.x (for different x
) of scala-compiler
are generally binary incompatible because it's not API like scala-library
or scala-reflect
. But twirl-compiler
is just _2.12
, not _2.12.x
.
[IJ][playdemo] $ projects
[info] In file:/playdemo/
[info] * root
[IJ][playdemo] $ reload plugins
[IJ]projects
[info] In file:/playdemo/project/
[info] * project
[IJ]dependencyTree
[info] default:project:0.1.0-SNAPSHOT
[info] +-com.typesafe.play:sbt-plugin:2.7.9
[info] | +-...
[info] | +-com.typesafe.sbt:sbt-twirl:1.4.2
[info] | | +-com.typesafe.play:twirl-compiler_2.12:1.4.2 [S]
[info] | | +-com.typesafe.play:twirl-api_2.12:1.4.2 [S]
[info] | | | +-...
[info] | | |
[info] | | +-com.typesafe.play:twirl-parser_2.12:1.4.2 [S]
[info] | | +-org.scala-lang:scala-compiler:2.12.15 [S]
[info] | | +-...
[info] | | +-org.scala-lang:scala-reflect:2.12.15 [S]
(running sbt command on the meta-build level)
Maybe this can be debugged like in SBT gives java.lang.NullPointerException when trying to run spark ...