How to reduce jar size while using maven-assembly-plugin in pom.xml for building spark application

Viewed 357

I am using the below plugin: maven-assembly-plugin in my pom.xml file with many other separate dependencies mentioned in the same file as below to build a jar file for my spark application using IntelliJ:

pom.xml Maven-assembly-plugin

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.5.3</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

pom.xml other dependencies:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-emr</artifactId>
    <version>1.11.125</version>
</dependency>

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.11.106</version>
</dependency>

to name a few..............!

What's happening is, this maven-assembly-plugin is bundling in all the dependency jars together with the main jar file and the size of the final jar file goes beyond 150+ Mb.

Is there a way in which I can mention only a particular dependency from my pom.xml to be included in the final jar file and excluding all the other dependencies??

With only this dependency included in the jar, hopefully, the final jar size should come down below 1 Mb.

The specific dependency which I want to include in my final jar is the below one:

<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20200518</version>
</dependency>
0 Answers
Related