AsyncAPI Generator Gradle Plugin
AsyncAPI Gradle Plugin
AsyncAPI Gradle plugin that delegates installation and execution of npm commands to com.github.node-gradle.node Gradle plugin.
This way one doesn’t need to care about node and npm installation within JVM project in order to use AsyncAPI generator.
Usage
To use the async generator in you Gradle build, apply the plugin:
plugins {
id "com.rivancic.asyncapi-gradle-plugin" version "0.1.0"
}
Plugin is available on Gradle Plugin Portal under com.rivancic.asyncapi-gradle-plugin.
Whole build script example:
plugins {
id("com.rivancic.asyncapi-gradle-plugin") version "0.1.0"
}
node {
download.set(true)
}
asyncapi {
asyncapi.set("https://bit.ly/asyncapi")
template.set("@asyncapi/html-template")
forceWrite.set(true)
version.set("1.9.7")
// debug.set(true)
// printVersion.set(true)
// output.set("build/asyncapi")
}
You will be able to execute code generation with gradlew generate command.
Generated code is by default placed in build/asyncapi folder.
Above is the view of the sample project in the IDE. On the right side there is generate Gradle task under asyncapi group.
If executed then build script form the middle screen is being executed. If node and npm aren’t yet installed they will
be installed locally under the .gradle directory. You can check packages and installed modules in that directory.
Configuration
One can configure following parameters through asyncapi extension:
asyncapi and template parameters are required to be set.
asyncapi {
// You want a specific version of the generator because your template might not be compatible with the latest
// generator. Check what version you need and perform installation, specifying the exact version.
version = "1.9.8"
// Local path or URL pointing to AsyncAPI specification file
asyncapi = null
// Name of the generator template like for example <i>@asyncapi/html-template</i> or
// <i>https://github.com/asyncapi/html-template</i>
template = null
// Directory where to put the generated files (defaults to current directory)
output = "build/asyncapi"
// Output the version number
printVersion = false
// Enable more specific errors in the console
debug = false
// Force writing of the generated files to given directory even if it is a git repo with unstaged files or not empty
// dir (defaults to false)
forceWrite = false
// Additional parameters that will be passed to templates. Have to be provided as a map.
parameters = [:]
}
It’s planned to support all the AsyncAPI CLI options.
Additionally one can leverage configuration
of com.github.node-gradle.node plugin with node extension. For example:
node {
download = false
version = "16.14.0"
}
Tasks:
| Task | Description |
|---|---|
generate |
Generate code based on the configuration form variables |
assemble |
Depends on generate task |
clean |
Basic clean task, will delete build directory |