# How to create a fat-jar for a Spring project

**URL:** <https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941>\
**Category:** Old Forum Archive\
**Created:** [October 21, 2011, 11:20pm UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941 "2011-10-21T23:20:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_molozian](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chris\_molozian](https://discuss.gradle.org/u/chris_molozian)\
**Post date:** [October 21, 2011, 11:20pm UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941/1 "2011-10-21T23:20:00Z")

</div>

I’d like to use Gradle as my build environment for a Java SE project involving Spring DI + Spring ORM. When I create a fat-jar of the program and it’s dependencies the META-INF/spring.schemas are duplicated and contain incomplete information.

What can I do to merge the schemas before adding them to the fat-jar?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [October 22, 2011, 10:06am UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941/2 "2011-10-22T10:06:00Z")

</div>

Depends on how you create the fat Jar. But if you truly need to merge the schemas (rather than selecting one of them to go into the fat Jar), you’ll have to do it yourself, with plain Groovy.

---

<div class="post-metadata">

**Author:** ![chris\_molozian](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chris\_molozian](https://discuss.gradle.org/u/chris_molozian)\
**Post date:** [October 22, 2011, 10:10am UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941/3 "2011-10-22T10:10:00Z")

</div>

I’m creating the fat-jar through the mechanism recommended in the Gradle Cookbook ([http://wiki.gradle.org/display/GRADLE/Cookbook#Cookbook-Includeallruntimedependencies](http://wiki.gradle.org/display/GRADLE/Cookbook#Cookbook-Includeallruntimedependencies)). e.g.

` jar {`

dependsOn configurations.runtime

from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } }

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [October 22, 2011, 11:04am UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941/4 "2011-10-22T11:04:00Z")

</div>

If you want to include just some of the schemas, you can do something like this:

```gradle
jar {
  ...
  from {
     configurations.runtime.collect { file ->
      if (file.directory) return file
      if (shouldIncludeSchemasFrom(file)) return zipTree(file)
      zipTree(file).matching { exclude "META-INF/spring.schemas/" }
      }
  }
}
  boolean shouldIncludeSchemasFrom(File file) { ... }

```

If you need true merging, you first have to somehow generate the merged files (probably as a separate task), and then include them into the fat Jar while excluding the original files.

---

<div class="post-metadata">

**Author:** ![chris\_molozian](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chris\_molozian](https://discuss.gradle.org/u/chris_molozian)\
**Post date:** [October 22, 2011, 11:35am UTC](https://discuss.gradle.org/t/how-to-create-a-fat-jar-for-a-spring-project/5941/5 "2011-10-22T11:35:00Z")

</div>

That’ll do the trick. Thank you.
