HiveMQ Extension Gradle Plugin 2.0.0 Released
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.
settings.gradle.kts
build.gradle.kts
Once you apply the HiveMQ Extension plugin to your project, you can configure all the important HiveMQ Extension properties directly in your build file.
build.gradle.kts
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)
You can build your HiveMQ Extension with:
Assemble Additional Files Into Your Extension Folder
Files inside the src/hivemq-extension
folder is automatically included in your HiveMQ Extension zip.
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 from
, exclude
, include
, rename
, etc. (for a detailed explanation see the Gradle documentation). (for a detailed explanation see the Gradle documentation)
build.gradle.kts
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.
build.gradle.kts
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.
Add the HiveMQ Testcontainer as Dependency
Integration test dependencies are defined via the integrationTestImplementation
, integrationTestRuntimeOnly
, etc. configurations. So you can add all the dependencies you need for integration testing:
build.gradle.kts
Implement Your Integration Test
The integrationTest
task builds the Extension first and unzips it to the build/hivemq-extension-test
directory. The tests can then load the built Extension into a HiveMQ Test Container:
Conclusion
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.
HiveMQ Team
The HiveMQ team loves writing about MQTT, Sparkplug, Industrial IoT, protocols, how to deploy our platform, and more. We focus on industries ranging from energy, to transportation and logistics, to automotive manufacturing. Our experts are here to help, contact us with any questions.