On the deprecation of GroovySourceSet

The doc page for GroovySourceSet states:

Using convention to contribute to source sets is deprecated. You can configure the groovy sources via the GroovySourceDirectorySet extension (e.g. sourceSet.getExtensions().getByType(GroovySourceDirectorySet.class).setSrcDirs(...)). This interface is scheduled for removal in Gradle 9.0.

Does this mean that it’s not going to be possible to configure Groovy source like before?

Will

sourceSets {
    main {
        groovy {
            srcDirs = ['src/groovy']
        }
    }
}

have to be replaced with

sourceSets {
    main.groovy.srcDirs = ['src/groovy']
}

in Gradle 9?

It’s pretty cool to be able to configure all Groovy aspects of a source set under closure.

I don’t think that is meant.
The GroovySourceDirectorySet is registered as extension with name groovy on a SourceSet, so the syntax should stay the same.
I think the comment is more for people for example using Java to write a plugin and previously using the GroovySourceSet.

Indeed, it seems like it’s going to continue to work as before (at least for Groovy). I tried it out in a small example. I defined my own simplified SourceDirectorySet for a dummy language:

interface DummySourceDirectorySet extends Named {
    DummySourceDirectorySet setFoo(boolean foo)
    boolean getFoo()
}

I followed the same pattern as for org.gradle.api.file.SourceDirectorySet to return the object from the setter. I’m guessing this is needed to support the configuration under a closure. I don’t really know how Gradle calls methods from the Groovy DSL.

I appled the Java plugin to get some source sets. I added an implementation of this class as an extension:

plugins {
    id 'java'
}

abstract class DefaultDummySourceDirectorySet implements DummySourceDirectorySet {
    // ...
}

sourceSets.main.extensions.create('dummy', DefaultDummySourceDirectorySet, 'mainDummy')

I tried to configure the main source set using a closure:

sourceSets {
    main {
        dummy {
            println it

            println "before: ${foo}"

            foo = true
            println "after: ${foo}"
        }
    }
}

It works as expected. It prints:

extension ‘dummy’
before: false
after: true

I guess the conventions currently only exist so that the API stays the same for Kotlin DSL users. Once they remove the conventions in Gradle 9 and leave just the extensions, Kotlin builds scripts will have to be updated. Groovy build scripts will still work.

The full build.gradle for reference:

plugins {
    id 'java'
}

interface DummySourceDirectorySet extends Named {
    DummySourceDirectorySet setFoo(boolean foo)
    boolean getFoo()
}

abstract class DefaultDummySourceDirectorySet implements DummySourceDirectorySet {
    private boolean foo;

    DummySourceDirectorySet setFoo(boolean foo) {
        this.foo = foo
        return this
    }

    boolean getFoo() {
        return foo
    }
}

sourceSets.main.extensions.create('dummy', DefaultDummySourceDirectorySet, 'mainDummy')

sourceSets {
    main {
        dummy {
            println it

            println "before: ${foo}"

            foo = true
            println "after: ${foo}"
        }
    }
}

I think they are kept for exactly those for which the JavaDoc is meant, for plugin authors that use conventions explicitly. I don’t expect and she’s change for Kotlin DSL either.