Lagom with Gradle - java.lang.NoClassDefFoundError: scala/Function1$class

Lagom with Gradle - java.lang.NoClassDefFoundError: scala/Function1$class

我正在尝试 运行 使用 Gradle 的 Lagom 服务 - 这似乎不是一个好主意,但出于学习目的我决定尝试一下。

您可以在此处浏览存储库: https://github.com/ashofthephoenix/lagom-gradle-helloworld

当我 cd 进入 hello-impl 并在控制台中执行 gradle -t runPlayBinary - 服务工作。

当我从项目级目录运行执行相同的命令时,它给了我这个堆栈跟踪:

java.lang.NoClassDefFoundError: scala/Function1$class
    at play.docs.Memoise.<init>(DocumentationHandler.scala:118)
    at play.docs.DocumentationHandler.<init>(DocumentationHandler.scala:26)
    at play.docs.DocumentationHandler.<init>(DocumentationHandler.scala:22)
    at play.docs.BuildDocHandlerFactory.fromJar(BuildDocHandlerFactory.java:88)
    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:498)
    at org.gradle.play.internal.run.DefaultVersionedPlayRunAdapter.getBuildDocHandler(DefaultVersionedPlayRunAdapter.java:140)
    at org.gradle.play.internal.run.PlayWorkerServer.startServer(PlayWorkerServer.java:91)
    at org.gradle.play.internal.run.PlayWorkerServer.start(PlayWorkerServer.java:76)
    at org.gradle.play.internal.run.PlayWorkerServer.execute(PlayWorkerServer.java:60)
    at org.gradle.play.internal.run.PlayWorkerServer.execute(PlayWorkerServer.java:36)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:83)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:35)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:119)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:64)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:62)
    at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:67)
Caused by: java.lang.ClassNotFoundException: scala.Function1$class
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more

有人能告诉我这里有什么问题吗?

谢谢。

虽然你的 build.gradle 文件有一些冗余,但它确实为我构建 gradle clean :hello-impl:runPlayBinary (是的,根级别 gradle runPlayBinary 确实像你的报告一样,但我认为你的游戏设置在你的 impl 模块中。)

如果 gradle clean :hello-impl:runPlayBinary 适合你,请告诉我。

$ gradle clean :hello-impl:runPlayBinary

> Task :hello-impl:compilePlayBinaryScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

--- (Running the application, auto-reloading is enabled) ---

16:07:45.432 [info] play.core.server.AkkaHttpServer [] - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

> Task :hello-impl:runPlayBinary
Running Play App (:hello-impl:runPlayBinary) at http://localhost:9000/


BUILD SUCCESSFUL in 6s
8 actionable tasks: 8 executed

Reloadable deployment detected. Entering continuous build.

> Task :hello-impl:compilePlayBinaryScala
Pruning sources from previous analysis, due to incompatible CompileSetup.


BUILD SUCCESSFUL in 8s
8 actionable tasks: 6 executed, 2 up-to-date

Waiting for changes to input files of tasks... (ctrl-d to exit)
16:07:55.872 [info] akka.event.slf4j.Slf4jLogger [] - Slf4jLogger started
16:07:56.323 [info] akka.remote.Remoting [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaSource=akka.remote.Remoting, sourceActorSystem=application, akkaTimestamp=21:07:56.322UTC] - Starting remoting
16:08:01.482 [info] akka.remote.Remoting [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaTimestamp=21:08:01.482UTC, akkaSource=akka.remote.Remoting, sourceActorSystem=application] - Remoting started; listening on addresses :[akka.tcp://application@10.0.0.173:2552]
16:08:01.484 [info] akka.remote.Remoting [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaTimestamp=21:08:01.483UTC, akkaSource=akka.remote.Remoting, sourceActorSystem=application] - Remoting now listens on addresses: [akka.tcp://application@10.0.0.173:2552]
16:08:01.498 [info] akka.cluster.Cluster(akka://application) [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaTimestamp=21:08:01.498UTC, akkaSource=akka.cluster.Cluster(akka://application), sourceActorSystem=application] - Cluster Node [akka.tcp://application@10.0.0.173:2552] - Starting up...
16:08:01.578 [info] akka.cluster.Cluster(akka://application) [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaTimestamp=21:08:01.578UTC, akkaSource=akka.cluster.Cluster(akka://application), sourceActorSystem=application] - Cluster Node [akka.tcp://application@10.0.0.173:2552] - Registered cluster JMX MBean [akka:type=Cluster]
16:08:01.579 [info] akka.cluster.Cluster(akka://application) [sourceThread=play-dev-mode-akka.actor.default-dispatcher-4, akkaTimestamp=21:08:01.578UTC, akkaSource=akka.cluster.Cluster(akka://application), sourceActorSystem=application] - Cluster Node [akka.tcp://application@10.0.0.173:2552] - Started up successfully
16:08:01.602 [info] akka.cluster.Cluster(akka://application) [sourceThread=application-akka.actor.default-dispatcher-15, akkaSource=akka.cluster.Cluster(akka://application), sourceActorSystem=application, akkaTimestamp=21:08:01.601UTC] - Cluster Node [akka.tcp://application@10.0.0.173:2552] - No seed-nodes configured, manual cluster join required
16:08:02.307 [info] play.api.http.EnabledFilters [] - Enabled Filters (see <https://www.playframework.com/documentation/latest/Filters>):


16:08:02.348 [info] play.api.Play [] - Application started (Dev)
<-------------> 0% WAITING

[更新]

这是 root 模块和 hello-impl 模块之间的组件任务差异。如您所见,root 模块和 hello-impl 模块的模块设置不同。

hello-impl 模块生成的工件将是最终交付物,因此据我所知,任务应该 运行 :hello-impl:runPlayBinary

Lagom 提供 sbt 和 Maven 插件,允许它们启动多个服务,向每个服务注入配置,并允许它们使用服务定位器相互发现。

要在 Gradle 中做同样的事情需要编写一个类似的 Gradle 插件。目前不存在这样的东西。 Gradle 的 Play 支持仅设计用于包含单个应用程序的传统 Play 项目。

有一个开放的功能请求,以向 Lagom (https://github.com/lagom/lagom/issues/146) 添加官方 Gradle 支持。