# Removing dependencies from a jar file during jar task

**URL:** <https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521>\
**Category:** Old Forum Archive\
**Created:** [March 19, 2013, 4:29pm UTC](https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521 "2013-03-19T16:29:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edvorkin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/edvorkin/32/291_2.png) [@edvorkin](https://discuss.gradle.org/u/edvorkin)\
**Post date:** [March 19, 2013, 4:29pm UTC](https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521/1 "2013-03-19T16:29:00Z")

</div>

I am trying to build a jar file with all runtime dependencies but exclude certain group. How to accomplish in in Gradle? Something like in Maven

```gradle
<exclude>commons-lang:commons-lang</exclude>

```

My code is:

```gradle
task stormJar(type: Jar) {
      archiveName "CPStorm.jar-${version}.jar"
    dependsOn configurations.runtime
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
    exclude('**/*storm*.jar')
    exclude('**/defaults.yaml')
    /*configurations.runtime {
        all.collect { configuration ->
            configuration.exclude group: 'storm', module: 'storm'
        }
    }*/
}

```

But instead storm.jar I would like to exclude whole dependency because it is already exists on server:

```gradle
compile 'storm:storm:0.8.2'

```

basically I am trying to accomplish this task but with Gradle: [https://github.com/nathanmarz/storm/wiki/Running-topologies-on-a-production-cluster](https://github.com/nathanmarz/storm/wiki/Running-topologies-on-a-production-cluster)

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [March 19, 2013, 6:14pm UTC](https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521/2 "2013-03-19T18:14:00Z")

</div>

Are you trying to create a ‘fat-jar’ with all of the dependency classes included directly? It looks like the ‘storm’ dependency is what’s referred to in Maven as ‘provided’ scope. In Gradle you can accomplish something similar by using a separate configuration.

Depending on what you’re trying to do, you could try manipulating configurations as described in GRADLE-784, or simply filter ‘storm\*.jar’ out of the fat-jar inputs. (You’re excludes above will be attempting to match on the class files that will end up in the archive, not the input files that provide them).

```gradle
task stormJar(type: Jar) {
    archiveName "CPStorm.jar-${version}.jar"
    from {
          configurations.runtime.filter( {! (it.name =~ /storm.*\.jar/ )}).collect {
             it.isDirectory() ? it : zipTree(it)
         }
     }

```

Or if you add the storm dependencies to an extra configuration, and subtract these from the inputs:

```gradle
configurations {
    storm
    compile.extendsFrom storm
}
dependencies {
    storm 'storm:storm:0.8.2'
}
task stormJar(type: Jar) {
    archiveName "CPStorm.jar-${version}.jar"
    from {
         (configurations.runtime - configurations.storm).collect {
             it.isDirectory() ? it : zipTree(it)
         }
     }

```

I haven’t tested either of these :). But something like this should work.

---

<div class="post-metadata">

**Author:** ![edvorkin](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/edvorkin/32/291_2.png) [@edvorkin](https://discuss.gradle.org/u/edvorkin)\
**Post date:** [March 19, 2013, 7:41pm UTC](https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521/3 "2013-03-19T19:41:00Z")

</div>

Thank you. You second suggestion is working. I was able to create fat jar but without storm dependencies.

```gradle
jar {
    archiveName "CPStorm-${version}.jar"
    dependsOn configurations.runtime
    from {
        (configurations.runtime - configurations.storm).collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![james\_sumners](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/james_sumners/32/1362_2.png) [@james\_sumners](https://discuss.gradle.org/u/james_sumners)\
**Post date:** [October 24, 2013, 6:17pm UTC](https://discuss.gradle.org/t/removing-dependencies-from-a-jar-file-during-jar-task/5521/4 "2013-10-24T18:17:00Z")

</div>

I have to say, this is really stupid:

```gradle
configurations {
  provided
  compile.extendsFrom provided
}
  dependencies {
  compile 'org.slf4j:slf4j-api:1.7.5'
      provided 'org.codehaus.groovy:groovy-all:2.1.8'
    runtime 'com.oracle:ojdbc16:11.2.0.4'
  runtime 'ch.qos.logback:logback-classic:1.0.13'
}
  jar {
  dependsOn configurations.runtime
  from {
    (configurations.runtime - configurations.provided).collect {
      it.isDirectory() ? it : zipTree(it)
    }
  }
}

```

Why not just add a “provided” to the default configurations?
