Fork me on GitHub

Usage

The plugin offers goals for controlling a test instance of Apache Cassandra from Apache Maven.

Basic Usage

Before you start it is best to add cassandra-maven-plugin as a plugin in your pom.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Start up a test instance of Cassandra

To start up a test instance of Cassandra invoke the run goal.

mvn cassandra:run

You can change the ports that Cassandra binds to either using the cassandra.nativeTransportPort, cassandra.jmxPort, cassandra.storagePort and cassandra.stopPort properties from the command line, e.g.

mvn cassandra:run -Dcassandra.nativeTransportPort=19042 -Dcassandra.jmxPort=17199 -Dcassandra.storagePort=17000 -Dcassandra.stopPort=18081

Or in the configuration block in the plugin definition (which has the advantage that all invokations will use the same parameters.

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
        <configuration>
          <nativeTransportPort>19042</nativeTransportPort>
          <jmxPort>17199</jmxPort>
          <storagePort>17000</storagePort>
          <stopPort>18081</stopPort>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Adding dependencies to the classpath

There are a number of ways to add dependencies to the classpath used to start Cassandra.

The simplest way is just to add a dependency to the plugin definition, e.g. to add jna support you would just configure the plugin like this (assuming that the version of jna you specify is available from the repositories you are using):

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
        ...
        <dependencies>
          <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>3.2.7</version>
          </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

This can give you issues if you want to use custom column comparators which are built from within the same Maven reactor as the project which is consuming them (Note: the long reason for this is as follows: With Maven 2.x the plugin classpath is not rebuilt for each project which will give you one set of problems. With Maven 3.x the plugin classpath is rebuilt for each project, but your build plan will be dependent on the output of the build which could potentially invalidate the build plan, so Maven 3.x will not let you do that!)

To add dependencies from the reactor you either add the main classpath or the test classpath (which implies the main classpath as well)

So we could also achieve the same jna support as the above example in two other ways:

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>net.java.dev.jna</groupId>
      <artifactId>jna</artifactId>
      <version>3.2.7</version>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
        <configuration>
          <addMainClasspath>true</addMainClasspath>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

or

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>net.java.dev.jna</groupId>
      <artifactId>jna</artifactId>
      <version>3.2.7</version>
      <scope>test</scope>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
        <configuration>
          <addTestClasspath>true</addTestClasspath>
        </configuration>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Using alternative cassandra version.

By default the cassandra version is 4.0.11, but you can override that by adding cassandra-all as a plugin dependency.

This may not work for all cassandra versions, but if you do not stray too far from the default version it should work.

Example:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cassandra-maven-plugin</artifactId>
        <version>4.0.0</version>
        ...
        <dependencies>
            <dependency>
                <groupId>org.apache.cassandra</groupId>
                <artifactId>cassandra-all</artifactId>
                <version>3.7</version>
            </dependency>
        </dependencies>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

Trademarks

Apache, Apache Maven, Apache Cassandra, Maven, Cassandra and the Apache feather logo are trademarks of The Apache Software Foundation.