rapt
rapt

Reputation: 12240

Scala build.sbt: Memcached Plugin for Play framework 2.8.6

I am trying to upgrade mumoshu's Memcached Plugin for Play framework, to Play 2.8.6, in build.sbt.

The upgrade instructions are:

For Play 2.6.x and newer: !!! Changed play.modules.cache.* config keys to play.cache.* !!!

val appDependencies = Seq(
  play.PlayImport.cacheApi,
  "com.github.mumoshu" %% "play2-memcached-play26" % "0.9.2"
)
val main = Project(appName).enablePlugins(play.PlayScala).settings(
  version := appVersion,
  libraryDependencies ++= appDependencies,
  resolvers += "Spy Repository" at "http://files.couchbase.com/maven2" // required to resolve `spymemcached`, the plugin's dependency.
)

Before the upgrade, I had:

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,  
  "com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0",
  //...
}

After the (unsuccessful) upgrade:

The updated build.sbt now looks like this:

name := "CH07"

version := "1.0"

lazy val `ch07` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.13.4"

resolvers += "Spy Repository" at "http://files.couchbase.com/maven2"

val appDependencies = Seq(
  play.sbt.PlayImport.cache,
  "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0"
  //"com.github.mumoshu" %% "play2-memcached-play26" % "0.9.2"
)
val main = (project in file(".")).enablePlugins(play.sbt.PlayScala).settings(
  version := version.value,
  libraryDependencies ++= appDependencies,
  resolvers += "Spy Repository" at "http://files.couchbase.com/maven2" // required to resolve `spymemcached`, the plugin's dependency.
)

libraryDependencies ++= Seq(
  jdbc,
  //cache,
  ws,

  "org.hsqldb" % "hsqldb" % "2.5.0",
  "org.jooq" % "jooq" % "3.14.4",
  "org.jooq" % "jooq-codegen-maven" % "3.14.4",
  "org.jooq" % "jooq-meta" % "3.14.4",
  "joda-time" % "joda-time" % "2.7",
  "com.github.ironfish" %% "akka-persistence-mongo-casbah"  % "0.7.6",
  "com.ning" % "async-http-client" % "1.9.29"
)

routesGenerator := InjectedRoutesGenerator

Errors I am getting:

* build.sbt:
error: value cache is not a member of object play.sbt.PlayImport

* build.sbt:
"com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0"
Intellij says: unresolved artifact. Not resolved or indexed.

* in project/plugins.sbt:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.6")
Intellij says: unresolved artifact. Not resolved or indexed.

Can you see any errors I made in the build.sbt?

In other words, I am looking for a working build.sbt (and the other required definitions) example for a project that uses Play 2.8.6 and the Memcached Plugin for Play framework 0.9.2. (or highest possible version of the latter).

UPDATE:

This is my current configuration which does compile:

build.sbt

name := "CH07"

version := "1.0"

lazy val `ch07` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.13.4"

resolvers += "Spy Repository" at "http://files.couchbase.com/maven2"

libraryDependencies ++= Seq(
  jdbc,
  cacheApi,
  ws,
  "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0",
  "org.hsqldb" % "hsqldb" % "2.5.0",
  "org.jooq" % "jooq" % "3.14.4",
  "org.jooq" % "jooq-codegen-maven" % "3.14.4",
  "org.jooq" % "jooq-meta" % "3.14.4",
  "joda-time" % "joda-time" % "2.7",
  "com.ning" % "async-http-client" % "1.9.29",
  "com.github.scullxbones" %% "akka-persistence-mongo-common" % "3.0.5",
  "com.typesafe.akka" %% "akka-persistence" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-query" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-typed" % "2.6.10",
  "com.typesafe.play" %% "play-guice" % "2.8.7"
)

routesGenerator := InjectedRoutesGenerator

project/build.properties

sbt.version=1.3.10

project/plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")

Upvotes: 1

Views: 633

Answers (2)

Tomer Shetah
Tomer Shetah

Reputation: 8539

Your issue is when trying to import play.sbt.PlayImport.cache. According to Cache APIs Migration by play:

New packages

Now `cache` has been split into a `cacheApi` component with just the API, and `ehcache` that contains the Ehcache implementation. If you are using the default Ehcache implementation, simply change `cache` to `ehcache` in your `build.sbt`:
libraryDependencies ++= Seq(
  ehcache
)

If you are defining a custom cache API, or are writing a cache implementation module, you can just depend on the API:

libraryDependencies ++= Seq(
  cacheApi
)

Removed APIs

The deprecated Java class play.cache.Cache was removed and you now must inject an play.cache.SyncCacheApi or play.cache.AsyncCacheApi.

Therefore a complete build.sbt will be:

name := "CH07"

version := "1.0"

lazy val `ch07` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.13.4"

resolvers += "Spy Repository" at "https://files.couchbase.com/maven2"

val appDependencies = Seq(
  play.sbt.PlayImport.ehcache,
  play.sbt.PlayImport.cacheApi,
  "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0"
  //"com.github.mumoshu" %% "play2-memcached-play26" % "0.9.2"
)
val main = (project in file(".")).enablePlugins(play.sbt.PlayScala).settings(
  version := version.value,
  libraryDependencies ++= appDependencies,
  resolvers += "Spy Repository" at "https://files.couchbase.com/maven2" // required to resolve `spymemcached`, the plugin's dependency.
)

libraryDependencies ++= Seq(
  jdbc,
  //cache,
  ws,

  "org.hsqldb" % "hsqldb" % "2.5.0",
  "org.jooq" % "jooq" % "3.14.4",
  "org.jooq" % "jooq-codegen-maven" % "3.14.4",
  "org.jooq" % "jooq-meta" % "3.14.4",
  "joda-time" % "joda-time" % "2.7",
  "com.github.scullxbones" %% "akka-persistence-mongo-common" % "3.0.5",
  "com.ning" % "async-http-client" % "1.9.29"
)

routesGenerator := InjectedRoutesGenerator

build.properties:

sbt.version=1.4.4

plugins.sbt:

logLevel := Level.Warn

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")

Upvotes: 1

rysh
rysh

Reputation: 131

How about this?

name := """pla-memcache-example"""
organization := "com.example"

version := "1.0-SNAPSHOT"

scalaVersion := "2.13.3"

val appDependencies = Seq(
    guice,
    play.PlayImport.cacheApi,
    "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0",
    "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
)

lazy val root = (project in file(".")).enablePlugins(PlayScala).settings(
    version := appVersion,
    libraryDependencies ++= appDependencies,
    resolvers += "Spy Repository" at "http://files.couchbase.com/maven2" // required to resolve `spymemcached`, the plugin's dependency.
  )

plugins.sbt

sbt.version=1.3.13

plugins.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")

In this case, first find the giter8 template and use the "sbt new" command. Next, go to the official page of the plugin and check the name of the library, and then use Maven search to find the version you want to use. It's a good idea to read the entire readme of the plugin without skipping it.

You can also try to run sbt with commands instead of using IntelliJ.
If that doesn't solve the problem, you can try clearing the cache in the .ivy2 directory.

Reference Links:
https://github.com/mumoshu/play2-memcached
https://github.com/playframework/play-scala-seed.g8
https://search.maven.org/artifact/com.github.mumoshu/play2-memcached-play28_2.13/0.11.0/jar

Upvotes: 1

Related Questions