Are dependencies supposed to be packaged with a maven jar artifact?

714 views Asked by At

Sonatype's Maven:The Complete Reference says that a compile scoped dependency is on all classpaths and is packaged with the artifact.

Compile is the default scope; all dependencies are compile-scoped if a scope is not supplied. compile dependencies are available in all classpaths, and they are packaged.

I can't see that they are packaged though . . . doesn't this mean that they should be contained in the jar file? If not, what does it mean?

1

There are 1 answers

2
Pradeep Fernando On

You are correct. Compiled scope dependencies does not get packaged with the output jar. (with JAR plugin). I think the 'package' refers to the end product (binary executable).

I came across this stackOverflow thread (How can I create an executable jar with dependencies using Maven?). Here they are packaging all the dependencies to build a executable out of Main class. In that case you need all the compile time dependencies in your packaged executable. (since JAVA lazy loads it is not a must, but preferable to have all the compile time dependencies)