What is the best way to publish an all-jar for a multi-project build?

So I have a project with several sub-projects. In the subprojects block I have defined:

subprojects {
    tasks.withType(Jar).all { jarTask ->
    manifest {
      attributes("Artifact": baseName, "Group": rootProject.group, "Build-Version": version)
    }
  }
    task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    classifier = 'sources'
  }
    task reportsZip(type: Zip, dependsOn: projectReport) {
    from dependencyReport.outputFile.parent
    classifier = 'reports'
  }
    artifacts {
    archives sourcesJar
    archives reportsZip
  }
}

This publishes the jars just fine (individually) for each subproject. Now, I want to build and publish a jar that is an aggregate of all of the subproject jars. I tried this in the root project build.gradle:

subprojects.each { subproject ->
   evaluationDependsOn(subproject.path)
}
  task allJar(type: Jar, dependsOn: subprojects.jar) {
   baseName = 'myproject-all'
   subprojects.each { subproject ->
     from subproject.configurations.archives.allArtifactFiles.collect {
       zipTree(it)
     }
   }
}
  artifacts {
  archives allJar
}

When I try to build this, I get the following error:

Could not find method archives() for arguments [task ‘:allJar’] on root project

I am at a loss to what I am missing. Do I need to add this artifact to the configuration somehow?

Sorry… I was missing a crucial line in the root build.gradle:

apply plugin: 'maven'

The error indicates that the root project doesn’t have an ‘archives’ configuration. Are you sure you are still getting this after applying the Maven plugin? Do you apply the Maven plugin at the top of the build script?