Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source in test/resources directory will get compiled in Play 2

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?

like image 617
Sonson123 Avatar asked Oct 07 '12 18:10

Sonson123


Video Answer


1 Answers

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"
like image 85
Schleichardt Avatar answered Oct 23 '22 00:10

Schleichardt