How to set gradle plugin version from gradle plugin written in Kotlin/Java?

311 Views Asked by At

So I'm writing a plugin using Kotlin and in such plugin (my plugin), I install other plugins.

From the project object I can access the plugins field, and its methods. Yet there's no method that allows me to pick the version I'm gonna install of the plugin.

Basically I want to do the equivalent of

plugins{
  id "org.jetbrains.kotlin.jvm" version "1.6.21"
}

But in my plugin the only available object (project.plugins) is of type PluginContainer, which basically only has the method apply(String) and the method apply(Class<?>). How do I specify the version of the plugin using this interface?

1

There are 1 best solutions below

2
On

I'll call the plugin you're developing "your plugin" and the plugin you want to apply as the "sub plugin".

To specify the version of the sub plugin, in the build.gradle of your plugin, you specify the GAV (group:artifact:version) of the sub plugin, and it's that version that'll be used when you apply the sub plugin in your plugin.