1

I have a huge dependency (Spark) that I use in compileOnly configuration, and several other libraries. I am trying to build a fat jar, of course, without compileOnly dependencies. Gradle does this fine, however, several libraries declare compile/runtimeOnly dependencies that are also dependencies of compileOnly huge dependency, like:

my-module
|-> compileOnly: spark
|   ...
|   \-> compile: scala-reflect
|   ...
\-> implementation: library
    ...
    \-> runtimeOnly: scala-reflect

That causes scala-reflect to be included into jar as runtime dependency, that I am trying to avoid. Scala is taken here only as example, there are actually more like that (Jackson, parts of Apache Commons, …).

Is there way to enforce compileOnly trainsitional dependencies?

As I can see, I can manually exclude those transitive dependencies and redeclare them as compileOnly, but that would be a little mess (did I miss any? did I excluded something that is not actually provided?).

Lapshin Dmitry
  • 1,084
  • 9
  • 28
  • How do you build the fatjar? – Peter Jul 01 '19 at 15:16
  • I am using [`shadow` plugin](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) that takes outputs of compilation and, by default, adds everything from `runtimeClasspath` configuration. I am trying not to add something to `runtimeClasspath`. – Lapshin Dmitry Jul 01 '19 at 15:44

1 Answers1

0

You can try to enforce the shadow plugin to remove those unneeded dependencies via the dependencies directive.

for example:

shadowJar {
  dependencies {
    exclude(dependency('org.scala-lang:scala-reflect:.*'))
  }
}

More info here https://imperceptiblethoughts.com/shadow/configuration/dependencies/#filtering-dependencies

Abbas Gadhia
  • 14,532
  • 10
  • 61
  • 73