How do I create a tarball of my multi project?

I have multiple projects as part of my gradle project.

Root

– Project 1

– Project 2

I would like ./gradlew build to finish building the individual sub projects, drop their jars in Project1/build folders and then create a tarball of the entire project and drop it in Root/build/. How do I do this? I tried something like what is shown below and I get the error “Could not find property ‘assemble’ on root project”

task explodedDist(dependsOn: assemble) << {

File explodedDist = mkdir("$buildDir/explodedDist")

subprojects.each {project ->

project.tasks.withType(Jar).each {archiveTask ->

copy {

from archiveTask.archivePath

into explodedDist

}

}

} }

Did you have any luck solving this problem? Could you please share the solution?