Referencing Java 'sourceSets.main.java' in a task in Kotlin build script

I was playing around with the Java plugin and the Kotlin DSL. I wanted to write a simple task that copies the files in the main source set to the build directory.

I tried doing the following:

tasks.register<Copy>("copy") {
    from(sourceSets.main.java.files)
    into("build")
}

This fails with an “unresolved reference” error.

Thanks to the excellent IDE integration, I could immediately see that sourceSets.main returns an object of type NamedDomainObjectProvider<org.gradle.api.tasks.SourceSet>, not of type SourceSet. To get it to work, I have to do add an extra get() call:

tasks.register<Copy>("copy") {
    from(sourceSets.main.get().java.files)
    into("build")
}

Is this by design? Is there a reason why the shorter form isn’t supported?

For reference, in Groovy it would look like this:

task copy(type: Copy) {
    from sourceSets.main.java.files
    into "build"
}

Maybe it just takes a bit of getting used to, but having to add the get() isn’t very intuitive.