HiveMQ Extension Gradle Plugin 2.0.0 released
Written by Yannick Weber
Published: July 6, 2021
The HiveMQ team is proud to present a new version of the HiveMQ Extension Gradle Plugin. This plugin lets you take advantage of everything Gradle has to offer. For example,
- incremental builds,
- better dependency management, and
- scripting your build configuration.
To make it even easier to set up a complete Gradle build pipeline for your HiveMQ Extension, we’ve created a new version of the HiveMQ Extension Gradle Plugin that registers all the basic tasks you need from start to finish. The new version adds the following advantages:
- Improved API
- Automatic setup for integration testing
Example HiveMQ Extension build with Gradle
Let’s take a look at how to create a HiveMQ Extension with Gradle. In this example we use the Kotlin DSL for the Gradle scripts.
First, to apply the
com.hivemq.extension Gradle plugin,
add the following lines to the build files that are located at the root of your project.
Once you apply the HiveMQ Extension plugin to your project, you can configure all the important HiveMQ Extension properties directly in your build file.
You may notice strong similarities between the
hivemq-extension.xml you used to create and bundle into your Extension zip.
The Gradle plugin creates the XML file for you and fills in all the required properties.
The Gradle plugin also generates the
META-INF/services/com.hivemq.extension.sdk.api.ExtensionMain service descriptor file.
Just specify the mainClass entry point of the Extension as shown above.
That is all you need to create a HiveMQ Extension with Gradle.
To assemble your Extension, simply execute the
hivemqExtensionZip Gradle task that executes all the other tasks needed to create the finalized zip of your HiveMQ Extension.
When the task is done, the zip file appears in the
build/hivemq-extension folder of your project folder.
We recommend using a Gradle wrapper so that every build uses the same Gradle version. To initialize the Gradle wrapper, execute the following command in your project folder. (Gradle version 6 or higher is required)
gradle wrapper --gradle-version=7.1.1
You can build your HiveMQ Extension with:
Assemble additional files into your Extension folder
Files inside the
src/hivemq-extension folder are automatically included in your HiveMQ Extension zip.
hivemq-hello-world-extension ├─ src │ ├─ hivemq-extension // Everything here is added to the Extension folder in the zip │ ├─ main // Everything here is used to generate the jar archive │ │ ├─ java // Your code │ │ └─ resources // Resources inside the jar, do not put resources for the zip here │ └─ test │ ... ├─ build.gradle.kts └─ settings.gradle.kts
Additionally, you can use
hivemqExtension.resources to add custom resources from any location or Gradle task.
hivemqExtension.resources is of type
CopySpec, so you can use
rename, etc. (for a detailed explanation see the Gradle documentation).
(for a detailed explanation see the Gradle documentation)
Debug your Extension directly from your IDE
The HiveMQ Gradle plugin lets you run your Extension with HiveMQ directly from your IDE. This enables you to quickly debug and test your Extension. To use this feature, you need to download HiveMQ Enterprise or Community Edition first and unzip it somewhere suitable.
For example, add the following lines to your build file.
Integration testing with the HiveMQ Testcontainer
The HiveMQ Extension Gradle Plugin 2.0.0 adds an
integrationTest task that executes tests from the
integrationTest source set.
hivemq-hello-world-extension ├─ src │ ├─ main │ │ ├─ java // Your code │ │ └─ resources │ ├─ integrationTest │ │ ├─ java // Your integration testing code │ │ └─ resources │ └─ test │ ... ├─ build.gradle.kts └─ settings.gradle.kts
Add the HiveMQ Testcontainer as dependency
Integration test dependencies are defined via the
integrationTestRuntimeOnly, etc. configurations.
So you can add all the dependencies you need for integration testing:
Implement your integration test
integrationTest task builds the Extension first and unzips it to the
The tests can then load the built Extension into a HiveMQ Test Container:
The HiveMQ Extension Gradle plugin version 2.0.0 further simplifies developing, debugging, and building HiveMQ Extensions with Gradle. With version 2.0.0 the ability for integration testing without boilerplate is added.
Have a great day,
Yannick from the HiveMQ Team