The Gradle Mongo Plugin allows you to run a managed instance of Mongo from your gradle build. It is based on the Embedded MongoDb project by Flapdoodle OSS.
Plugin is available on Maven Central. Nightly builds are available from the Sonatype OSS Repo.
Enable the plugin in your gradle build by adding the jar to your buildscript dependencies:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.sourcemuse.gradle.plugin:gradle-mongo-plugin:0.6.0'
}
}
apply plugin: 'mongo'
Hey presto...
$ gradle tasks
...
Mongo tasks
-----------
startManagedMongoDb - Starts a local MongoDb instance which will stop when the build process completes
startMongoDb - Starts a local MongoDb instance
stopMongoDb - Stops the local MongoDb instance
...
Configure your Mongo instance inside a mongo block:
mongo {
port 12345
logging console
...
}
The following properties are configurable:
bindIp: The ip address Mongo binds itself to (defaults to '127.0.0.1')journalingEnabled: Toggles journaling (defaults to false)logFilePath: The desired log file path (defaults to 'embedded-mongo.log')logging: The type of logging to be produced: 'console', 'file' or 'none' (defaults to 'file')mongoVersion: The version of Mongo to run. Can be 'DEVELOPMENT' or 'PRODUCTION' for the latest versions of the respective branch, or take the form '1.2-LATEST' or '1.2.3' for specific versionsport: The port Mongo will listen on (defaults to 27017). For random port assignment, set this value to 'RANDOM' (the actual port value used will be available during the build through the project.mongo.port property)storageLocation: The directory location from where embedded Mongo will run, such as/tmp/storage(defaults to a java temp directory)