[Guice] JUnit using running(fakeApplication()) in IntelliJ is broken #39

mbknor opened this Issue Sep 25, 2012 · 2 comments


None yet
2 participants

mbknor commented Sep 25, 2012

Play 2.0.3 Java with dependency to Gucie plugin 2.0.3 breaks running JUnit tests that uses running(fakeApplication()) with the following exception:

net.sf.ehcache.ObjectExistsException: Cache play already exists
    at net.sf.ehcache.CacheManager.addCache(CacheManager.java:990)
    at play.api.cache.EhCachePlugin.x$3(Cache.scala:111)
    at play.api.cache.EhCachePlugin.cache(Cache.scala:109)
    at play.api.cache.EhCachePlugin.onStart(Cache.scala:127)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:60)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at play.api.Play$.start(Play.scala:60)
    at play.api.Play.start(Play.scala)

The cause of the problem is probably caused by play.plugins (referring to EhCachePlugin) being found multiple times on class path.

The problem can be reproduced like this:

Create new empty Java Play 2.0.3 project.

Add dependency to Guice module:

"com.typesafe" % "play-plugins-guice" % "2.0.3"

Create IntelliJ config:

play idea

Load project into IntelliJ and create the following JUnit test:

import org.junit.Test;

import static play.test.Helpers.fakeApplication;
import static play.test.Helpers.running;

public class PluginProblemTest {

    public void test() {
        running(fakeApplication(), new Runnable() {
            public void run() {
                System.out.println("Will not work when we have dep to Guice plugin");

Run the test from within IntelliJ and it will fail with the exception above


mbknor commented Sep 25, 2012

Found a workaround, by specifying dependencies like this:

      "com.typesafe" % "play-plugins-guice" % "2.0.3" notTransitive(),
      "com.google.inject" % "guice" % "3.0",
      "com.typesafe"  %    "play-plugins-inject"  %   "2.0.3"  notTransitive(),

I'm not using guice but also have this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment