Get monitoring, observability, online education,
and expert support from Lightbend.
Learn More

Build Cloudflow Applications using Maven

The default build tool for Cloudflow applications is sbt but there is support for using Maven to build as well.

In the examples directory you can find some reference projects compiled with Maven. Folders are marked with a mvn- prefix.

The Cloudflow maven plugin can be included in the plugins section:

<plugin>
  <groupId>com.lightbend.cloudflow</groupId>
  <artifactId>cloudflow-maven-plugin</artifactId>
  <version>${cloudflow.plugin.version}</version>
</plugin>

For Docker we support and integrate the workflow with fabric8 docker-maven-plugin.

Maven Workflow

Using a Cloudflow Maven project you can use the following Maven goals:

  1. package your application in a .jar

  2. cloudflow:extract-streamlets to make the Streamlets implementation available for the next steps

After using the goals mentioned above, you can perform a few interesting commands to analyze and develop your application locally:

  • cloudflow:verify-blueprint will verify that the provided blueprint.conf is valid

  • cloudflow:app-layout will print the graph of interconnections of the streamlets

  • cloudflow:run-local will run the application on forked JVMs locally

To deploy your application to a cluster you instead need the following steps:

  1. docker:build to build the docker images

  2. cloudflow:push-images to push the images to a Docker registry, returning information about the published image digests

If not specifically configured in your POM, the default image registry used by the fabric8 docker-maven-plugin is docker.io. To use a different registry, you’ll need to provide a proper <registry> subelement to your configuration. For more information, please see Registry handling.
  1. cloudflow:build-app to produce the deployable CR file in the topLevel project target directory

Full example

A full example of using the Maven commands is shown below:

  1. Set the $DOCKER_USERNAME and $DOCKER_PASSWORD environment variables to the username and password of your image registry.

    To avoid storing your credentials in the shell’s history file, use the following commands to create an environment variable for username and password. The username/password are your credentials to the Lightbend docker repository - commercial-registry.lightbend.com). If you want to see the password, remove the -s (for silent) flag.
      read DOCKER_USERNAME
      read -s DOCKER_PASSWORD
  2. Then execute the following:

    mvn clean
    mvn \
      package \
      cloudflow:extract-streamlets \
      docker:build \
      cloudflow:push-images \
      -Ddocker.username=${DOCKER_USERNAME} \
      -Ddocker.password=${DOCKER_PASSWORD} \
      -DskipTests
    mvn cloudflow:build-app
  3. After executing the above maven commands, you are ready to deploy your application to a cluster using:

    kubectl cloudflow deploy ./target/<your-application-name>.json

Archetype

You can easily generate a full project with akka streamlets using the Cloudflow Maven Archetype:

mvn archetype:generate -DarchetypeGroupId=com.lightbend.cloudflow \
  -DarchetypeArtifactId=cloudflow-archetype \
  -DarchetypeVersion=2.3.0 \
  -DgroupId=<groupId> \
  -DartifactId=<appId> \
  -Dversion=<version>

Configuration

The Maven plugin exposes some configuration keys that can be used to tweak the behavior. You can apply those by adding a configuration section such as:

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>com.lightbend.cloudflow</groupId>
            <artifactId>cloudflow-maven-plugin</artifactId>
            <version>${cloudflow.plugin.version}</version>
            <configuration>
              ...
            </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

The available configurations for the goal cloudflow:run-local are:

localConfig

String

Specify an alternative configuration file to be used in run-local

log4jConfigFile

String

Specify an alternative log4j configuration file to be used in run-local

baseDebugPort

Int

The initial port to be used for exposing JMX debugging

remoteDebug

Boolean

Enable JMX debugging during run-local