无法将带有子项目的已编译的 scala play 应用程序部署到 Heroku



我有一个游戏项目,由子项目组成,我在Heroku上使用。我正在使用带有 Scala 2.11.4 的 Play 2.3

目标

  • 我想从部署周期。我有两个主要驱动因素:我觉得对于生产代码我想部署jar而不是源代码
  • 汇编Heroku 花费的时间大约是我机器上的编译时间的十倍

方法

我的方法是将项目罐"发布"到 Maven,然后发布一个仅使用已发布工件的项目。这在我的机器上有效,但是当我将其部署到 Heroku 时,它无法编译:它找不到"控制器"。反转XXX'。

我的实际应用程序现在是数千个文件,但是我已经设法通过github上可用的一个小得多的项目重现了这个问题。我正在部署到本地自包含的 maven 存储库,以缓解此问题的重复。重现问题所需的两个项目是 https://github.com/stave-escura/mainChildPlayApp 和 https://github.com/stave-escura/deploy

重现问题的步骤

git clone https://github.com/stave-escura/mainChildPlayApp.git
cd mainChildPlayApp
git clone https://github.com/stave-escura/deploy.git
sbt
>publish
>run
    {At this point if you go to localhost:9000 you should see Main Hello world and localhost:9000/child should produce Child Hello World}
    {terminate the run with Ctrl-d}
exit
cd deploy
sbt
>run
    {At this point if you go to localhost:9000 you should see Main Hello world and localhost:9000/child should produce Child Hello World}
    {terminate the run with Ctrl-d}
>exit
heroku git:remote -a  <put in here the git repository details for your heroku app>
git add --all :/
git commit -m "Initial Commit"
git push --force heroku master

即使该项目在本地工作(由运行检查),它在 Heroku 上失败,并显示如下消息

   [error] /tmp/scala_buildpack_build_dir/target/scala-2.11/src_managed/main/controllers/routes.java:16: error: package controllers.ref does not exist
   [error] public static final controllers.ref.ReverseApplication Application = new controllers.ref.ReverseApplication();

正在发生的事情的摘要:

我的项目目录是

Project
   app
      ...
   conf
      ...
   public
      ...
   deploy
   modules
      child
         conf
         public
      main
         conf
         public

在发布过程中,我制作了一个 SBT 插件来复制 conf 和公共目录进行部署(合并它们),并且我也将 maven 工件发布到部署下的子目录。因此,发布后的部署结构变为

Project
  ...
  Deploy
    Conf
    Public
    Maven

我在部署目录中的 sbt 看起来像这样

organization := "org.myorg"
version := "1.0-SNAPSHOT"
scalaVersion := "2.11.4"
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Local" at new File("maven").toURI.toURL+"snapshots"
libraryDependencies +=    "org.myorg" %% "proj" % "1.0-SNAPSHOT"
lazy val deployedWebsite = (project in file(".")).enablePlugins(PlayScala)

它是发送到 Heroku 的部署目录中的 git 存储库。

免責聲明

我已经按照这些说明设法在我的机器上复制了错误。如果它们不适合您(说明错误,或者您得到不同的结果),请告诉我。像这样的报告问题很复杂!

最好的解决方案是 sbt-heroku 插件。这是希罗库的支持。它还没有很好地处理子项目,但是子项目存在悬而未决的问题,希望很快就会得到解决。

最新更新