List plugins and its version from another plugin?

Good morning,

I want to create a task in a plugin that list all the others plugins and their versions.

How can I achive it using kotlin?

I have tried this: project.configurations.getByName("compile").dependencies but it gives me an error telling:

Configuration with name 'compile' not found.

I have tried also with classpath but same error

You cannot really do it.
What you actually try is to list all compile dependencies of the actual project, while the compile configuration is long time deprecated and also non-existent by now as you see.
classpath also does not work, as on the actual project there is no such configuration and even if it were, it would not contain what you are after. classpath only exists on build script instances by default, but it might also not contain all dependencies you are after.

Iirc, what you probably need to do is to iterate over project.plugins to get the applied plugins and then do some classpath searching, getting the class loader from the plugin class, searching which jar the class comes from to extract the version from the jar name or some similar hackery.

1 Like

I got this working 30 mins ago with:

  val plugin = project.plugins.find {
      it.javaClass.simpleName == "PluginClass"

You can obtain version and additional information spliting, slicing the string