Help with exclusions from shadowJar


(Jens Deppe) #1

I’m trying to use the shadowJar plugin to create a jar which only contains all of the dependencies of my project but not my project’s code.

I’ve tried excluding my project from the dependencies with:

version = "1.0"
group = "com.pivotal"
  shadowJar {
  mergeServiceFiles()
  dependencies {
    exclude(dependency("com.pivotal:scratch:1.0"))
  }
}

But that leaves me with only my code in the jar produced by the shadowJar task. Actually, it doesn’t matter what I put in that dependency, it only leaves me with my classes.

I am using Gradle 1.12 and shadowJar 1.0.2.

Thanks --Jens


(John Engelman) #2

The best way to do this would be to create a new ‘ShadowJar’ task that produces your output:

task jarAllDeps(type: ShadowJar) {

from configurations.runtime

baseName = ‘scratch-dependencies’

}


(Jens Deppe) #3

Great, thanks for the response - I’ll try this.

On a side note, I noticed some weirdness in that shadowJar produces different results when ‘dependencies { }’ comes after ‘shadowJar { }’ in my gradle file. Is this some Gradleism (sorry, I’m a noob here) or a bug?

The weirdness here is what I mentioned above - the presence of ‘exclude’ seems to only result in my classes in the resulting jar.


(John Engelman) #4

Sounds like a bug, can you file an issue on the project site and I’ll take a look? https://github.com/johnrengelman/shadow/issues

If you have an example project that exhibits the problem, that would be great, just post it to Github or wherever and put a link to it in the issue. (Or just post your build.gradle file in the issue)