Using Version Catalogs with Precompiled Script Plugins

Suppose I have a precompiled script plugin which contains something like

plugins {
    // Picking a random plugin out of a hat here
    id("org.jlleitschuh.gradle.ktlint")
}

And suppose in the project I have a version catalog like so:

[plugins]
# Version omitted for the sake of an example
ktlint="org.jlleitschuh.gradle.ktlint"

According to the instructions, I need to declare this plugin as an implementation dependency in order for the precompiled script plugin to function properly. Given the catalog above, how would I populate the dependencies block in my build.gradle.kts?

See

So hopefully in 8.3 there is a built-in way.

In the meantime you can use a manual work-around like

dependencies {
    implementation(libs.plugins.ktlint.dependency)
}

val Provider<PluginDependency>.dependency
    get() = map { "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version}" }

I would also like to add my solution here without using any hacks.

The idea is simple. Since precompiled script plugins usually are a completely separated Gradle project (as long as you use includeBuild() to import your precompiled script plugins), we can just consume the version catalog in the build.gradle.kts that build up your precompiled script plugins (not the build.gradle.kts that builds up the main application)

The solution was focusing on adding a precompiled script plugins for setting plugin (Plugin<Setting>), but it is the same idea for project plugin (Plugin<Project>)

How is your post related to the thread here @CXwudi?
The question here is, if you have a plugin in the [plugins] section of the version catalog,
how do you use that in implementation(<here>) as dependency for a plugin project.

Oh, I see, I misunderstood the question by only reading the title and the first post only. I further read the linked GitHub issues and the PR you posted, and now I see the question.

Sorry for the confusing post.