How to alter dependencies for a generated artifact?

530 Views Asked by At

Gradle 2.3; shadow plugin 1.2.1.

In my build.gradle, I use the shadow plugin in order to repackage a dependency, like such:

shadowJar {
    relocate("com.google.common", "r.com.google.common");
}

I also add the shadow jar to the list of artifacts to publish:

artifacts {
    archives jar;
    archives sourcesJar;
    archives javadocJar;
    archives shadowJar;
}

However the list of dependencies of the shadow jar still contains all the dependencies of the "normal" jar, even though it has every dependency builtin.

Is this the intended behavior? How can I make the shadow jar exclude this or that dependency?

1

There are 1 best solutions below

0
On

Here at work we had the same problem and we just put this in a build.gradle of one of our projects:

def installer = install.repositories.mavenInstaller
def deployer = uploadArchives.repositories.mavenDeployer

[installer, deployer]*.pom*.whenConfigured { pom ->
    pom.dependencies.retainAll {
        it.groupId == 'our.group.id' && it.artifactId == 'some-api'
    }
}

This removes all dependencies from the pom.xml except for the dependency on one of our API projects.

(And it is a pretty verbatim copy of an example from the official Gradle documentation.)