Accessing project.buildscript from within Plugin<Project>#apply(Project)

What is the cleanest way that Kotlin code within Plugin<Project>#apply(project: Project) can configure project.buildscript?

I’m writing a Gradle plugin to configure all of my Gradle projects, and I want to lock plugin dependency configurations for all of them.

The following code works in a build.gradle.kts:

buildscript {

But the following doesn’t work from a Kotlin plugin:

override fun apply(project: Project) {
	project.buildscript {

This seems to be because the first of the following methods exists, but the second doesn’t:

Project#buildscript(Action<? super DependencyLockingHandler> action)

I’d imagine that calling something like the following could create the correct closure, but it seems hard to get this function available in my plugin:

delegateClosureOf(action: T.() -> Unit)

I could probably kludge something together to make this work, but I’d rather learn how to do this nicely. When I searched online, I got tons of unrelated results.