前提・実現したいこと
scala、playframeworkを使って作成したwebアプリケーションをherokuを用いてデプロイしようとしたところ、エラーが出てしまい、うまくいきません。
herokuを用いないかつh2を使ったローカル環境では正常に動作しています。
エラーの原因はどこにあり、どうすればエラーを解消することができるのか教えていただきたいです。
発生している問題・エラーメッセージ
remote: Pruning sources from previous analysis, due to incompatible CompileSetup. remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:5: not found: object anorm remote: import anorm.SqlParser._ remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:6: not found: object anorm remote: import anorm._ remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:7: object db is not a member of package play.api remote: import play.api.db.DBApi remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:14: not found: type DBApi remote: class TodoService @Inject() (dbapi: DBApi) { remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:19: not found: value get remote: get[Option[Long]]("todo.id") ~ remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:20: not found: value get remote: get[String]("todo.name") map { remote: ^ remote: /tmp/build_167204999ca2006747d425001b02dd2c/app/services/Todo.scala:21: not found: value ~ remote: case id~name => Todo(id, name) remote: ^ remote: 7 errors found remote: :compilePlayBinaryScala FAILED remote: remote: FAILURE: Build failed with an exception. remote: remote: * What went wrong: remote: Execution failed for task ':compilePlayBinaryScala'. remote: > Compilation failed remote: remote: * Try: remote: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. remote: remote: * Get more help at https://help.gradle.org remote: remote: BUILD FAILED in 59s remote: 4 actionable tasks: 4 executed
該当のソースコード
「Todo.scala」
scala
1 2package services 3 4import javax.inject.Inject 5 6import anorm.SqlParser._ 7import anorm._ 8import play.api.db.DBApi 9 10import scala.language.postfixOps 11 12case class Todo(id:Option[Long], name: String) 13 14@javax.inject.Singleton 15class TodoService @Inject() (dbapi: DBApi) { 16 17 private val db = dbapi.database("default") 18 19 val simple = { 20 get[Option[Long]]("todo.id") ~ 21 get[String]("todo.name") map { 22 case id~name => Todo(id, name) 23 } 24 } 25 26 def list(): Seq[Todo] = { 27 28 db.withConnection { implicit connection => 29 30 SQL( 31 """ 32 select * from todo 33 """ 34 ).as(simple *) 35 36 } 37 38 } 39 40 def insert(todo: Todo) = { 41 db.withConnection { implicit connection => 42 SQL( 43 """ 44 insert into todo values ((select next value for todo_seq), {name}) 45 """ 46 ).on( 47 'name -> todo.name 48 ).executeUpdate() 49 } 50 } 51 52 def findById(id: Long): Option[Todo] = { 53 db.withConnection { implicit connection => 54 SQL("select * from todo where id = {id}").on('id -> id).as(simple.singleOpt) 55 } 56 } 57 58 def update(id: Long, todo: Todo) = { 59 db.withConnection { implicit connection => 60 SQL( 61 """ 62 update todo 63 set name = {name} 64 where id = {id} 65 """ 66 ).on( 67 'id -> id, 68 'name -> todo.name 69 ).executeUpdate() 70 } 71 } 72 73 def delete(id: Long) = { 74 db.withConnection { implicit connection => 75 SQL("delete from todo where id = {id}").on('id -> id).executeUpdate() 76 } 77 } 78 79}
試したこと
dbにh2を利用していたことが原因かと考えherokuのpostgreSQLに移行(初の試みのため正常に接続できているかは不明)したが、エラーメッセージに変化なし。
anormが導入されていないのかとbuild.sbtを確認するが、
libraryDependencies += "com.typesafe.play" %% "anorm" % "2.5.3"
の記述はなされている。
補足情報(FW/ツールのバージョンなど)
環境
scala 3.1.2
java 8
anorm 2.5.3
build.sbt
scalaVersion := "2.12.4" libraryDependencies += guice libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test libraryDependencies += jdbc libraryDependencies += evolutions libraryDependencies += "com.typesafe.play" %% "anorm" % "2.5.3"
あなたの回答
tips
プレビュー