1

So, I have a multi-module project that I create a shaded jar for to add to non-maven projects as well as to support other maven projects. We have some of our own libraries as dependencies. However, bundling them in the shaded jar is causing issues in the non-maven application that already has those dependencies (and cannot be just removed to rely on the shaded version). I've been trying to make a profile in my project's pom to exclude these dependencies from the shaded jar but maven doesn't seem to care.

I can't post the entire pom but in essence, each module depends on other modules, and at the end we have a final module that just bundles everything together which is where my profile resides. I've added a list of dependencies that all have exclusions for the artifacts I don't want added to the shaded jar, I've used dependency:tree to add every module that has a transitive dependency to the exclusion and added a dependency entry for it along with its own exclusion, I've added an artifactSet to the shade plugin configuration to exclude those artifacts, and I've added the enforce plugin to fail the build if that artifact exists.

The artifact I don't want added is still being added to the shaded jar.

<dependencies>
    <dependency>
        <groupId>my.group</groupId>
        <artifactId>my-module</artifactId>
        <version>1.2.3</version>
        <exclusions>
            <exclusion>
                <groupId>some.dependency</groupId>
                <artifactId>i-dont-want</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

This works, but the problem is that I need to also have a dependency for a module further down the dependency tree that transitively depends on the above module.

So, when I do the following, the dependency I'm trying to exclude ends up in the shaded jar anyway.

<dependencies>
    <dependency>
        <groupId>my.group</groupId>
        <artifactId>my-module</artifactId>
        <version>1.2.3</version>
        <exclusions>
            <exclusion>
                <groupId>some.dependency</groupId>
                <artifactId>i-dont-want</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>my.group</groupId>
        <artifactId>dependes-on-my-module</artifactId>
        <version>1.2.3</version>
    </dependency>
</dependencies>

If I try to add exclusions in my shade config as below, it doesn't seem to care, either.

<configuration>
    <artifactSet>
        <excludes>
            <exclude>some.dependency:i-dont-want</exclude>
        </excludes>
    </artifactSet>
    ...
</configuration>

I've tried searching online and have probably tried a ton of stuff on stack overflow that hasn't seemed to help (even marking things as provided in my profile or adding all the dependencies that have a transitive dependency to the artifact I'm trying to remove with no luck).

Is there any way I can force these transitive dependencies to not be added to my shaded jar? I just want to not have them added; at this point I'll try anything... thanks for help in advance.

Stephen
  • 751
  • 1
  • 5
  • 6
  • 2
    IMHO, using a uber or fat jar as dependency for another project is nearly always a bad idea. You run into the problems you describe: The dependency that is inside the fat jar is also present at a different point and you get strange effects in the project, often at runtime. On the other hand, what do you gain from having a fat jar library? Maven automatically resolves transitive dependencies (so no need for fat jars), and for legacy ant projects, you can just copy the folder of transitive dependencies instead of one fat jar. So why do you want a fat jar? – J Fabian Meier Oct 25 '19 at 17:44
  • Because the netbeans platform isn't maven and a ton of transitive dependencies is more of a pain than just using a fat jar. – Stephen Oct 25 '19 at 17:49
  • "netbeans platform isn't maven": What do you mean by that? Do you create plugins/extensions for Netbeans? At least in any Maven context I would avoid fat jars. – J Fabian Meier Oct 25 '19 at 18:57
  • If an artifact is still being added it means it coming from one other dependency usually as transitive dependency. – khmarbaise Oct 26 '19 at 08:02
  • The netbeans application we have uses ant and not maven. There's also a lot of other users that don't want to use maven; using a non-shaded jar isn't an option, unfortunately. However, I did find out that another dev added a shade plugin section in another module; no problem with my profile just a dev adding something where they shouldn't have and confusing everyone – Stephen Oct 27 '19 at 02:25

1 Answers1

0

Ended up being a dev adding a shade plugin in another module that ended up getting the transitive dependency included in itself and passed along. Aside from maven not seeming to have a way to just nuke something from orbit it seems to be working now.

Stephen
  • 751
  • 1
  • 5
  • 6