The source in the test / resources directory will be compiled in Play 2

I want to transfer the Maven project to Play 2 / sbt:

I had 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 https://stackoverflow.com/a/260248/ ... ).

This works for regular files (text, binary data ...), but now I have problems with Java-Source files, which are also in the test/resources/ directory (I need to check the Java parser in my project for different java source files) . When I call test in the game, these files will also be compiled, and therefore I get errors.

How can I prevent the files in test/resources/ being compiled from Play / sbt?

+6
source share
2 answers

Since your test resources directory is located in a directory that compiles java sources, you can move the test resources folder. Add this to your settings:

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

For example, in the /Build.scala project:

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

Manage your changes in the console with

 play "show test:resource-directory" 
+8
source

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

Remember to leave an empty line between these lines. Remember to declare to eclipse the source folders. You will also need to add import to 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 that you could do

 play test play test-only xxx.yyy.zzz.TheTest play eclipsify 
+2
source

Source: https://habr.com/ru/post/927146/


All Articles