7

I want to migrate a Maven project to Play 2/sbt:

I had some resources for tests in src/test/resources in the Maven project, which I moved to test/resources/ in the Play project (thanks to Schleichardt for his answer on Stackoverflow).

This works for normal files (text, binary data...), but now I have problems with Java-Source files that are also in the test/resources/ directory (I have to test a Java parser in my project on different java source files). When I call test in play, these files will also get compiled and so I get errors.

How can I prevent that the files in test/resources/ will get compiled from Play/sbt?

Community
  • 1
  • 1
Sonson123
  • 10,879
  • 12
  • 54
  • 72

2 Answers2

9

Since your test resource directory is in a directory that compiles java sources you could move your test resource folder. Add this to your settings:

resourceDirectory in Test <<= (baseDirectory) apply {(baseDir: File) => baseDir / "testResources"}

For example in project/Build.scala:

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
    resourceDirectory in Test <<= (baseDirectory) apply  {(baseDir: File) => baseDir / "testResources"}
)

Control your changes in the console with:

play "show test:resource-directory"
Schleichardt
  • 7,502
  • 1
  • 27
  • 37
2

If you want to add test-resources you should modify project/Build.scala by adding the following to your PlayProject .... .settings(

Don't forget to leave an empty line between these lines. Don't forget to declare to eclipse the source folders. Also you will need to add an import before the PlayProject line

import com.typesafe.sbteclipse.core.EclipsePlugin._ 

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(defaultScalaSettings:_*).settings(

    ,resourceDirectory in Test <<= baseDirectory(_ / "test-resources")

    ,EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

)

After this you could do

play test
play test-only xxx.yyy.zzz.TheTest
play eclipsify
raisercostin
  • 8,777
  • 5
  • 67
  • 76
  • I still have some issues with resources that are not found when I run from Eclipse, but I think this is a step forward to a working eclipse solution for me. – Sonson123 Apr 25 '13 at 11:41