# Another 'fat Jar' question - multiple subprojects one jar

**URL:** <https://discuss.gradle.org/t/another-fat-jar-question-multiple-subprojects-one-jar/9732>\
**Category:** Help/Discuss\
**Created:** [May 21, 2015, 3:33pm UTC](https://discuss.gradle.org/t/another-fat-jar-question-multiple-subprojects-one-jar/9732 "2015-05-21T15:33:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzn](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dzn/32/2398_2.png) [@dzn](https://discuss.gradle.org/u/dzn)\
**Post date:** [May 21, 2015, 3:33pm UTC](https://discuss.gradle.org/t/another-fat-jar-question-multiple-subprojects-one-jar/9732/1 "2015-05-21T15:33:39Z")

</div>

Hi,

I found a bunch of ‘fatJar’ questions all over the internet and tried to implement my own solution. I can’t get it working however. This is what I currently have;

```
def allJarSubprojects = subprojects.findAll {
    it.name == 'subproject1' ||
    it.name == 'subproject2 ||
    it.name == 'subproject3'
}

// We need to make sure the relevant subprojects are evaluated first.
allJarSubprojects.each { subproject -> evaluationDependsOn(subproject.path) }

// Actual task producing the fat jar.
task allJar(type: Jar) {
    baseName = 'fatjar'
    destinationDir = new File('./lib')

    // set dependencies of this allJar task
    allJarSubprojects.each { subproject -> dependsOn subproject.tasks["classes"] }

    // create a jar from all the subproject's artifacts
    allJarSubprojects.each { subproject ->
        // no property 'allArtifactFiles'
        //from subproject.configurations.archives.allArtifactFiles.collect { zipTree(it) } 

        // works but doesn't pack the META-INF or other extra folders
        //from subproject.sourceSets.main.output

       // works but packs all dependencies of the subprojects too which we don't want
       //from subproject.configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

```

I am trying to keep the list of subprojects to be packed easy to configure so I can do it from the properties file later on.

The second line I have (based on sourceSets) works but doesn’t include some special META-INF files from some subprojects ( like a gradle-plugins folder ).

The third approach packs everything, all dependencies of the subprojects too, into one gigantic Jar. This is not the objective, I only want the subproject’s files in there.

It feels like the ‘allArtifactFiles’ approach would do that but I can’t get that one working.

---

<div class="post-metadata">

**Author:** ![Gary\_Hale](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/gary_hale/32/7647_2.png) [@Gary\_Hale](https://discuss.gradle.org/u/Gary_Hale)\
**Post date:** [May 22, 2015, 12:09pm UTC](https://discuss.gradle.org/t/another-fat-jar-question-multiple-subprojects-one-jar/9732/2 "2015-05-22T12:09:28Z")

</div>

You should be able to use `subproject.configurations.archives.artifacts.files` (see [dsl reference for Configuration](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html)).

And you’ll probably want to depend on the ‘jar’ task of subprojects instead of classes - classes just assembles the classes and resources but not the jar.
