Is there a recommended way to support multiple versions of a Plugin in my Gradle plugin?
My use case:
I’ve developed a plugin to remove a lot of the repository- and credentials-related (boilerplate)code from my other Gradle builds. One of the things this plugin should do is configuring the builder and run image and registries in all BootBuildImage tasks, if the org.springframework.boot
plugin is applied:
pluginManager.withPlugin("org.springframework.boot") {
// configure Docker registry in all BootBuildImage tasks.
// the `all` action will be executed against all current and future elements of the collection.
tasks.withType(BootBuildImage::class.java).all { task ->
val dockerPullRegistryUrl = myExtension.dockerPullRegistryUrl.get()
task.builder = "${dockerPullRegistryUrl}/paketobuildpacks/builder:base"
task.runImage = "${dockerPullRegistryUrl}/paketobuildpacks/run:base-cnb"
task.docker { docker ->
docker.builderRegistry { registry ->
registry.url = dockerPullRegistryUrl
registry.username = myExtension.dockerPullRegistryUsername.get()
registry.password = myExtension.dockerPullRegistryPassword.get()
}
docker.publishRegistry { registry ->
registry.url = myExtension.dockerPushRegistryUrl.get()
registry.username = myExtension.dockerPushRegistryUsername.get()
registry.password = myExtension.dockerPushRegistryPassword.get()
}
}
}
}
This works fine in my plugin using version 2.7.16
as the dependency. Now I also want to support version 3.X
. Unfortunately they broke compatibility in that version by changing the fields of DockerSpec.DockerRegistrySpec from String
to Property<String>
.
The only real solution, that comes to my mind is having multiple versions of the plugin supporting the two versions. Is there another one? Maybe even something to support both in the same plugin (version)?