GBDev
GBDev

Reputation: 42

Shade all dependencies of another dependency (hibernate) into jar

I'd like to automatically shade all the dependencies of Hibernate core into my main jar, without defining them explicitly (As this just seems to become a goose chase).

I can't just shade everything into my jar, as other dependencies are not needed and it would make my jar unnecessarily huge.

Is it possible to get maven to automatically shade all of the dependencies of one of your top-level dependencies?

Upvotes: 1

Views: 387

Answers (2)

Ben Peters
Ben Peters

Reputation: 92

You can set the scope of the dependencies you don't want shaded to 'provided' and that'll flag to maven that the library is provided/assumed available at runtime.

The rest of your dependencies, which either don't a specified scope or have the 'compile' scope, should be those that your jar needs to have shaded.

Then just use something similar to this in your pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Upvotes: 1

Alex Voss
Alex Voss

Reputation: 176

The Shade plugin supports selective inclusion, exclusion, filtering and minimization of a jar. This should do the trick.

Upvotes: 0

Related Questions