shadow: ShadowJar not working with newer 'implementation' configuration

shadowJar task doesn’t works when using dependencies with newer ‘api’ or ‘implementation’ or ‘testImplementation’ configurations instead of ‘compile’ or ‘testCompile’ configuration.

for e.g:

shadowJar task is ineffective when using dependencies like:

dependencies { **implementation** 'org.apache.commons:commons-lang3:3.5' }

instead of:

dependencies { **compile** 'org.apache.commons:commons-lang3:3.5' }

Shadow Version

2+

Gradle Version

4.3+

Expected Behavior

Fat jar should be generated upon execution of shadowJar task

Actual Behavior

Fat jar not getting generated upon execution of shadowJar task

Gradle Build Script(s)

One sample snippet provided above and using following shadow task

shadowJar { classifier = '' baseName = artifactId destinationDir = file("${buildDir}/dist") manifest { attributes 'Implementation-Title': title, 'Implementation-Version': version, 'Main-Class': mainClassName } zip64 true } Note: variable are defined under gradle.properties

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 19
  • Comments: 23 (1 by maintainers)

Most upvoted comments

A working workaround is to manually allow resolving implementation configuration like this:

shadowJar {
    project.configurations.implementation.canBeResolved = true
    configurations = [project.configurations.implementation]
    // ...
}

P.S. I have no clue what consequences this action could have, but it at least does exactly what good ol’ compile configuration did. Use this at your own risk.

You need configurations.runtime instead, as it extends from both compile and implementation.

But why should you do that @qoomon? It is the same as using the runtimeClasspath configuration which is resolvable and extends those two and would just work and also is the default used, so just remove the whole snippet you showed and it will work exactly the same, without abusing configurations that are not meant to be resolved.

This is my working solution in kotlin

withType<ShadowJar> {
    // <WORKAROUND for="https://github.com/johnrengelman/shadow/issues/448">
    configurations = listOf(
        project.configurations.implementation.get(),
        project.configurations.runtimeOnly.get()
    ).onEach { it.isCanBeResolved = true }
    // </WORKAROUND>
}

@scpketer , the workaround with the implementation worked . I couldn’t find any other alternate … As we are getting the the compile is deprecated warning and will be removed in gradle 7.0 version , and yet the issue is not fixed with shadow plugin , i see this as the only option … Thank you

In fact, Gradle 7.0 still has this api

// gradle.kts
project.configurations.implementation.get().isCanBeResolved = true

Did you see my code snippet? It clearly seen that my snippet enables direct resolving of implementation configuration.

project.configurations.implementation.canBeResolved = true

Doh! :–) Thanks for clarifying and for the tip!

@CharlieReitzel Did you see my code snippet? It’s clearly seen that my snippet enables direct resolving of implementation configuration.

project.configurations.implementation.canBeResolved = true

I’m using this approach in my own project, and I can tell it does work.

We are using Gradle 5.0 and having the same issue.