Impact of the scope on the maven assembly plugin

For a Spark project I needed to bundle some dependencies and I found a few Stackoverflow answers that explained to add this section to your pom.xml:

<plugin>
	<artifactId>maven-assembly-plugin</artifactId>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>single</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<descriptorRefs>
			<descriptorRef>jar-with-dependencies</descriptorRef>
		</descriptorRefs>
	</configuration>
</plugin>

But once I packaged my application I ended up with a huge jar file. It contained everything the application needed.

My mistake was that the pom.xml did not contain the proper scope for each dependency and because of that they were all getting bundled into the jar.

Specified that a few were provided (provided) and it reduced the jar size considerably.

How a small missing piece can change other behaviours drastically.

Advertisements

Published by

m5c

Java developper that loves photography and good coffee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s