首页 文章

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

提问于
浏览
0

我正在尝试使用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

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

谢谢 .

2 回答

  • 1

    Lagom提供了sbt和Maven插件,允许它们启动多个服务,将配置注入每个服务,并允许它们使用服务定位器发现彼此 .

    要在Gradle中执行相同操作,需要编写类似的Gradle插件 . 目前不存在这样的事情 . Gradle的Play支持仅适用于包含单个应用程序的传统Play项目 .

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

  • 1

    虽然你的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
    

    [UPDATE]

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

    hello-impl 模块生成的工件将是最终可交付成果,因此从我可以看到,任务应该由 :hello-impl:runPlayBinary 运行 .

    Components task difference between root module and hello-impl module

相关问题