Gradle analogue to Maven 'unpack' option in assembly

Hi , I am trying to create a gradle jar containing junit tests and its dependencies, so that I can run them from command line. With my current approach I am able to create compiled tests and its dependencies, but all dependency libraries get unpacked by default and are present as class files within the main jar file.

task testJar(type: Jar) {
    from {
        configurations.unitTests.collect { it.isDirectory() ? it : zipTree(it) }

    from (sourceSets.test.output) {
        include(['com/myproj/robo/envite/unitTests/*.class', 'com/myproj/robo/envite/unitTests/abc/*.class', 'com/myproj/robo/envite/'])
    archiveFileName = "envite-tests.jar"
    duplicatesStrategy = DuplicatesStrategy.INCLUDE

The above code creates a jar containing all tests and their dependencies that are all unpacked. I am looking for something like a jar file containing more jar files inside it.

I was able to achieve it in Maven assembly by setting ‘unpack’ flag as false.


Is there any way to achieve the similar in gradle ?

The dependencies of the unitTests configuration are unpacked because of the use of zipTree. Are these the dependencies you are referring to? If so, using from configurations.unitTests should give you what you want.