How to programmatically get dependencies of a separate Kotlin Gradle project?

I have a Kotlin Gradle project A in another folder on a local disk.

Is it possible to check from a current project B what versions of plugins and dependencies are present in Project A?

Currently I see GradleRunner from which I can take and parse the output, but it would be great if there was another, more convenient way.

You should not parse the output.
Instead you should use the tooling API (already included if you are withing Gradle) to get information about the other build.
That is also exactly what IDEs use to get information about a build.

Versions of plugins could be hard to determine though, depending on where the versions are coming from, as you generally are not really able to get the actual version of a plugin, no matter which way you go afair.

Is it possible to register a custom ToolingModelBuilder without modifying the build.gradle.kts of the project where I want to use the custom model for ProjectConnection.getModel(...)?

To get the dependencies you can probably simply use the built-in IDE Models.
But yes, use an init script to inject build logic into a build.

I decided to use a custom plugin for injecting logic into the test project, but the precompiled plugin was not found.
To reproduce an error run org.example.tools.PluginTest from this repository

Are you aware that TestKit != Tooling API?
Tooling API is a productive library that e.g. IDEs use to get information about builds and also drive them.
TestKit is a tool to test plugins you develop.
They are in some parts partly similar but not to be confused.

Besides that, why should ScriptPlugin be available in tested-project?
ScriptPlugin is built in buildSrc of the build defined in project-for-testing-with-plugin/settings.gradle.kts which makes it available to all build scripts in that build.
But tested-project is not part of that build, it is a completely own standalone build.

Happy birthday! Thanks for answering the questions :slight_smile:

Here was mentioned about plugin classpath injecting into the code under test. But maybe I misunderstood, and it is not possible to use the plugin from the current test in a separate tested project.

Thanks. :slight_smile:
The TestKit is to test a plugin you develop.
So by doing withPluginClasspath() there, you get TestPlugin in the classpath of the build you run as that is the plugin you develop in the main source set of the test-plugin project.

ScriptPlugin is a plugin you have in buildSrc which is a separate own build, in which you build plugins that you use in the build script of your main build.