Home

Awesome

embedmongo-maven-plugin Build Status Maven Central

Maven plugin wrapper for the flapdoodle.de embedded MongoDB API.

This plugin lets you start and stop an instance of MongoDB during a Maven build, e.g. for integration testing. The Mongo instance isn't strictly embedded (it's not running within the JVM of your application), but it is a managed instance that exists only for the lifetime of your build.

Versions

Usage

<plugin>
  <groupId>com.github.joelittlejohn.embedmongo</groupId>
  <artifactId>embedmongo-maven-plugin</artifactId>
  <version>0.4.1</version>
  <executions>
    <execution>
      <id>start</id>
      <goals>
        <goal>start</goal>
      </goals>
      <configuration>
        <port>37017</port>
        <!-- optional, default 27017 -->
        
        <randomPort>true</randomPort>
        <!-- optional, default is false, if true allocates a random port and overrides embedmongo.port -->
        
        <version>2.0.4</version>
        <!-- optional, default 2.2.1 -->
        
        <features>ONLY_WITH_SSL, ONLY_WINDOWS_2008_SERVER, NO_HTTP_INTERFACE_ARG</features>
        <!-- optional, default is none. Enables flapdoodle.embed.mongo features, for example to build Windows download URLs since 3.6 -->
        
        <databaseDirectory>/tmp/mongotest</databaseDirectory>
        <!-- optional, default is a new dir in java.io.tmpdir -->
        
        <logging>file</logging>
        <!-- optional (file|console|none), default console -->
        
        <logFile>${project.build.directory}/myfile.log</logFile>
        <!-- optional, can be used when logging=file, default is ./embedmongo.log -->
        
        <logFileEncoding>utf-8</logFileEncoding>
        <!-- optional, can be used when logging=file, default is utf-8 -->
        
        <bindIp>127.0.0.1</bindIp>
        <!-- optional, default is to listen on all interfaces -->
        
        <downloadPath>http://internal-mongo-repo/</downloadPath>
        <!-- optional, default is http://fastdl.mongodb.org/ -->

        <unixSocketPrefix>${user.home}/.embedmongo</unixSocketPrefix>
        <!-- optional, default is /tmp -->
        
        <storageEngine>wiredTiger</storageEngine>
        <!--optional, one of wiredTiger or mmapv1 (default is mmapv1) -->
        
        <skip>false</skip>
        <!-- optional, skips this plugin entirely, use on the command line like -Dembedmongo.skip -->
        
      </configuration>
    </execution>
    <execution>
      <id>mongo-scripts</id>
      <goals>
        <goal>mongo-scripts</goal>
      </goals>
      <configuration>
        <version>2.0.4</version>
        <!-- optional, default 2.2.1 -->

        <scriptsDirectory>...</scriptsDirectory>
        <!-- a directory containing scripts to run -->
        
        <scriptCharsetEncoding>UTF-8</scriptCharsetEncoding>
        <!-- optional, valid charset encoding for loading the scripts. Uses the underlying charset encoding of the platform if not assigned -->
        
        <databaseName>mydb</databaseName>
        <!-- the name of the database to run scripts against -->
        
      </configuration>
    </execution>
    <execution>
      <id>mongo-import</id>
      <goals>
        <goal>mongo-import</goal>
      </goals>
      <configuration>
        <version>2.0.4</version>
        <!-- optional, default 2.2.1 -->

        <defaultImportDatabase>test</defaultImportDatabase>
        <!-- optional, name of the default database to import data -->
        
        <parallel>false</parallel>
        <!-- optional, default false, if true it launches in parallel all imports -->
        
        <wait>false</wait>
        <!-- optional, default false, if true it will wait forever after it imports the data -->
        
        <imports>
          <import>
            <database>my_db</database>
            <!-- optional, name of the database, if null it will fallback to defaultImportDatabase -->
            
            <collection>col</collection>
            <!-- optional, collection to import data into (will use <file> to derive this otherwise) -->
            
            <file>import_file.json</file>
            <!-- required, name of the json file to import -->
            
            <upsertOnImport>true</upsertOnImport>
            <!-- optional, default true, if true it will do an upsert on each document imported -->
            
            <dropOnImport>false</dropOnImport>
            <!-- optional, default true, if true it will do a drop the collection before starts to import -->
            
            <timeout>20000</timeout>
            <!-- optional, default 20000, it will fail if it takes more than this time importing a file (time in millis) -->
            
          </import>
          <!-- More imports are accepted and it will be executed in strictly order (if parallel is not set) -->
        </imports>
      </configuration>
    </execution>
    <execution>
      <id>stop</id>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Notes

Copyright © 2012 Joe Littlejohn