Download source JARs from maven and put them in a directory

I want to download JARs and put them in a directory. If I declare dependencies as transitive and set up a configuration with a classifier of ‘sources’ it only downloads first-level source JARs. It does get the transitive dependencies but only the non-source ones which is odd. Basically, I want to get all source JARs of my dependency, and all related source JARs and copy them to a directory. Here is my build.gradle:

defaultTasks 'run'

repositories {
    mavenCentral()
}

configurations {
    sources {
        description = 'sources download'
        transitive = true
    }
    copysource {
        extendsFrom sources
    }
}

dependencies {
    sources group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2', classifier: 'sources'
}


task copySources(type: Copy) {
    println 'Copying dependencies to sources directory'
    into "sources/"
    from configurations.copysource
}

task run (dependsOn: ['copySources']){
    println 'Downloading JARs'
}

run << {
    println 'Downloads complete. Finished.'
}

I see an answer on these forums from 2013 that might be relevant, but I am not sure if there is an easier way to do this now. Here is that older answer:

“Peter_Niederwieser: You’d essentially have to reimplement what the IDE plugins do - iterate over the resolved dependencies and try to resolve corresponding dependencies with ‘sources’ and ‘javadoc’ classifiers. It might be more worthwhile to investigate why the generated IDEA project crashes, or to try IDEA’s built-in Gradle support (preferably using a 12.1 EAP version).”