Is there a way to declare a test dependency in the dependencies.yml file for the Play! Framework? I don’t see any information about test dependencies in the documentation.
For example, I may want to use a testing library such as Mockito but not have its classes used in production for obvious reasons.
It seems that you can define dependencies per Play framework ID, similar to how you can define settings for a specific ID in the application.conf file. To do this, you need to add an additional
idattribute to your dependency definition.For example, if you wanted to only include mockito-core in environments with a framework ID of
test, your dependencies.yml file would look like the following:You can get this to work when using a single machine as well, although you have to be a bit more deliberate about it. To test with your test-only dependencies, you’d define your dependency with
id: testand then run:Then, to switch back to production, you’d run:
The downside is that you have to remember to sync your dependencies every time you switch between test and production modes, but I think that this is currently the best you can do if you want to make sure that the dependency is only on the classpath when in test mode.