Making Gradle plugin using Gradle 7 backaward compatible with Groovy 2.x

I wonder if there is a way to build a plugin using Gradle 7 (Groovy 3.x) and maintain compatibility with Gradle 6 (Groovy 2.x)?

As long as you don’t use Groovy 3 or Gradle 7 only features then your plugin should work in both.

If you need to use different Gradle features based on version, then you can use the GradleVersion class.