Debugging a Gradle plugin in IntelliJ IDEA

How can I debug a Gradle plugin in IntelliJ IDEA? (current version 2019.3.1)

I want to create a breakpoint in plugin code and debug it as it’s running.

Is there any built-in Gradle or IntelliJ support for this? Or any useful plugin for either?

Is creating a composite build that has includeBuild("path to plugin project") in its settings.gradle.kts the best way? If so, must the composite build be the root of the IntelliJ project? Or can I have the plugin code be the root, and the composite just a file in the project, and still somehow debug the composite from IntelliJ?

Thanks.

According this manual you should create test side-project and include your plugin as composite build.
After it, in your test project you only need to create simple stub task and debug it.
I generate simple project for demonstration this feature. Instruction in readme.md file.