[Play Framework 2] Play Redis Pluginを使う際の注意

2014.09.16

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Redis Pluginの導入でエラー

2014/09/12現在、Typesafeのリポジトリで提供されているRedis Pluginは、手順通りに導入してもエラーでCompileすらできません。

play-plugins / redis

導入するまでに結構な手間と調査の時間がかかったので、折角なのでブログに記述しておきます。

実行環境

  • Mac OSX 10.9.4
  • Play Framework Version 2.3.4
  • scalaVersion := "2.11.1"
  • java version "1.8.0_20"

導入手順(失敗)

公式のリポジトリに公開されている手順通りに記述を行います。

build.sbtを編集する

play < 2.3.x: "com.typesafe" %% "play-plugins-redis" % "2.0.4" to your dependencies
play = 2.3.x: "com.typesafe.play.plugins" %% "play-plugins-redis" % "2.3.0" to your dependencies

今回は、Play FrameworkのVersionは2.3.4なので後者を利用します。

name := """Play2Redis"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs,
  "com.typesafe.play.plugins" %% "play-plugins-redis" % "2.3.0"
)

play.pluginsを作成 or 編集する

play.pluginsファイルを編集します。存在しない場合はconf以下に作成します。

550:com.typesafe.plugin.RedisPlugin

application.confを編集する

最後にapplication.confの中にehcacheplugin=disabledの記述を追加します。

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

ehcacheplugin=disabled

設定の読み込み

準備が出来たのでReloadします。
プロジェクト配下でactivatorコマンドを叩いておきます。

[Play2Redis] $ reload
[info] Loading project definition from /Users/komuro/Develop/play/Play2Redis/project
[info] Set current project to Play2Redis (in build file:/Users/komuro/Develop/play/Play2Redis/)

コンパイル

コンパイルを実行します。

[Play2Redis] $ compile
[info] Updating {file:/Users/komuro/Develop/play/Play2Redis/}root...
[info] Resolving com.typesafe.play.plugins#play-plugins-redis_2.11;2.3.0 ...
[warn] 	module not found: com.typesafe.play.plugins#play-plugins-redis_2.11;2.3.0
[warn] ==== local: tried
[warn]   /Users/komuro/.ivy2/local/com.typesafe.play.plugins/play-plugins-redis_2.11/2.3.0/ivys/ivy.xml
[warn] ==== activator-local: tried
[warn]   file:/usr/local/Cellar/typesafe-activator/1.2.7/libexec/repository/com.typesafe.play.plugins/play-plugins-redis_2.11/2.3.0/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/com/typesafe/play/plugins/play-plugins-redis_2.11/2.3.0/play-plugins-redis_2.11-2.3.0.pom
[warn] ==== typesafe-releases: tried
[warn]   http://repo.typesafe.com/typesafe/releases/com/typesafe/play/plugins/play-plugins-redis_2.11/2.3.0/play-plugins-redis_2.11-2.3.0.pom
[warn] ==== typesafe-ivy-releasez: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play.plugins/play-plugins-redis_2.11/2.3.0/ivys/ivy.xml
[warn] ==== Typesafe Releases Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/com/typesafe/play/plugins/play-plugins-redis_2.11/2.3.0/play-plugins-redis_2.11-2.3.0.pom
[info] Resolving jline#jline;2.11 ...
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	::          UNRESOLVED DEPENDENCIES         ::
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	:: com.typesafe.play.plugins#play-plugins-redis_2.11;2.3.0: not found
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: com.typesafe.play.plugins#play-plugins-redis_2.11;2.3.0: not found
[error] Total time: 8 s, completed 2014/09/13 18:28:16

エラーになりました。
エラーログに書いてあるとおり、様々なリポジトリを探してもpluginが見つからなかったようです。

com.typesafe.play.plugins#play-plugins-redis_2.11;2.3.0: not found

導入手順(エラーを解消)

まずは、リポジトリの中に実態があるのかを確認します。

[warn] ==== Typesafe Releases Repository: tried
[warn]   http://repo.typesafe.com/typesafe/releases/com/typesafe/play/plugins/play-plugins-redis_2.11/2.3.0/play-plugins-redis_2.11-2.3.0.pom

Typesafe内のリポジトリを確認しているようですので、URLの追加設定は不要なようです。

手順1.Typesafeのリポジトリを確認する

build.sbtでも記述したように、Typesafeのリポジトリからcom.typesafe.play.pluginsが存在するかを確認します。
確認するURLは こちら

スクリーンショット 2014-09-13 18.35.42

ありました。play-plugins-redis_2.10 が確認できます。

現在のScalaのVersionは2.11。そもそも対象のディレクトリが存在しないため、not foundが返ってきていたようです。

手順2.対象のプラグインのScalaバージョンを固定

現在は、2.11に対応するリポジトリがないので2.10のディレクトリを参照します。今一度build.sbtに戻ってみます。

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs,
  "com.typesafe.play.plugins" %% "play-plugins-redis" % "2.3.0"
)

%%の指定で、ビルドする環境のScalaバージョンを自動的に補完して検索してくれるようです。厄介なのでバージョン固定で指定します。

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  javaWs,
  "com.typesafe" % "play-plugins-redis_2.10" % "2.1.1"
)

以上のように修正します。バージョン固定だけでなくパスも若干変更しているので注意してください

(さっき調べたリポジトリパスは何だったんだ!と思われるかもしれませんが、初めのパスですと、「Version Conflict」が発生し全くもってうまくいかなかったのでこうなっています。興味のある方はお試しください)

さて、これで再度準備が整いました。先ほどと同じく、reloadとcompileを実行します。

手順3.再実行

結果以下のようになります。

[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play/play-datacommons_2.10/2.3.0/play-datacommons_2.10-2.3.0.jar ...
[info] 	[SUCCESSFUL ] com.typesafe.play#play-datacommons_2.10;2.3.0!play-datacommons_2.10.jar (744ms)
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	::          UNRESOLVED DEPENDENCIES         ::
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[warn] 	:: org.sedis#sedis_2.10.0;1.1.1: not found
[warn] 	::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.sedis#sedis_2.10.0;1.1.1: not found
[error] Total time: 47 s, completed 2014/09/13 18:44:54

sedisは、Redis Pluginに依存するScalaのRedis Clientです。こいつもリポジトリが見つからないとのこと。

sedisのリポジトリを追加する

githubのissueにも書いてあるとおり、resolversにリポジトリのURLを追加します。

scalaVersion := "2.11.1"

resolvers += "Sedis Repo" at "http://pk11-scratch.googlecode.com/svn/trunk"

再度、reloadとcompileを実行します。

最終結果

[Play2Redis] $ reload
[info] Loading project definition from /Users/komuro/Develop/play/Play2Redis/project
[info] Set current project to Play2Redis (in build file:/Users/komuro/Develop/play/Play2Redis/)
[Play2Redis] $ compile
[info] Updating {file:/Users/komuro/Develop/play/Play2Redis/}root...
[info] Resolving jline#jline;2.11 ...
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-plugins-redis_2.10/2.1.1/play-plugins-redis_2.10-2.1.1.jar ...
[info] 	[SUCCESSFUL ] com.typesafe#play-plugins-redis_2.10;2.1.1!play-plugins-redis_2.10.jar (2637ms)
[info] downloading http://repo.typesafe.com/typesafe/releases/com/typesafe/play-plugins-util_2.10/2.1.1/play-plugins-util_2.10-2.1.1.jar ...
[info] 	[SUCCESSFUL ] com.typesafe#play-plugins-util_2.10;2.1.1!play-plugins-util_2.10.jar (1186ms)
[info] downloading http://repo1.maven.org/maven2/org/ow2/spec/ee/ow2-atinject-1.0-spec/1.0.10/ow2-atinject-1.0-spec-1.0.10.jar ...
[info] 	[SUCCESSFUL ] org.ow2.spec.ee#ow2-atinject-1.0-spec;1.0.10!ow2-atinject-1.0-spec.jar(bundle) (752ms)
[info] downloading http://repo1.maven.org/maven2/com/cedarsoft/guice-annotations/2.0.1/guice-annotations-2.0.1.jar ...
[info] 	[SUCCESSFUL ] com.cedarsoft#guice-annotations;2.0.1!guice-annotations.jar (757ms)
[info] downloading http://repo1.maven.org/maven2/com/intellij/annotations/7.0.3/annotations-7.0.3.jar ...
[info] 	[SUCCESSFUL ] com.intellij#annotations;7.0.3!annotations.jar (717ms)
[info] Done updating.
[info] Compiling 4 Scala sources and 2 Java sources to /Users/komuro/Develop/play/Play2Redis/target/scala-2.11/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.11.1. Compiling...
[info]   Compilation completed in 15.827 s
[success] Total time: 47 s, completed 2014/09/13 18:56:29

ようやく成功しました。これで、Play Frameworkの中でRedisが利用できるようになります。

まとめ

良いかどうかは別として、一つ前のVesrionのプラグインを導入するのにここまで苦労するとは予想外でした。

Scalaのバージョンを自動補完してくれたりする、便利なようで融通の効かないbuild.sbtの罠にハマリました。
あとで気づきましたが、このPluginsはもう公式にはメンテナンスされてないんですね。。
どなたか良いRedis Pluginの情報があれば教えて下さい。

最終的にcompileが成功したsbtファイルの設定はこちらになります。Typesafe RepoのResolvers設定はいらなかったかも。