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.
Unmanaged dependencies work like this: create a lib/ directory in the root of your project and then add jar files to that directory. They will automatically be added to the application classpath. There's not much else to it. There's nothing to add to build.
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 id
attribute 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:
require:
- org.mockito -> mockito-core 1.8.5:
id: test
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: test
and then run:
play dependencies --%test --sync
play test
Then, to switch back to production, you'd run:
play dependencies --sync
play 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With