I am not very much experienced with Maven and it's compilation and packaging logic gets me confused.
I have some dependencies declares as :
<dependency>
<groupId>com.dependency_group</groupId>
<artifactId>dependency_1</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.dependency_group</groupId>
<artifactId>dependency_2</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
So as far as I understand, dependency_1
will be added to the classpath of my program as something that comes along with my jar, and dependency_2
on the other hand, will be added to the classpath as something that the system runtime will provide upon deployment.
Then I run the package
goal of Maven and none of my dependencies are packed with my code (I am using the shade
plugin, but even without it nothing changes).
I expected that when some dependency is set as compile
scope
, it will be exported with my compiled code, since AFAICS, there's no point in setting the classpath saying a dependency will come along with my code, and Maven just don't package that dependency with it. It looks to me as if Maven is not obeying it's contract.
So:
1 - What's the logic behind this?
2 - Do I have to always use the Assembly plugin?
3 - Are there cases where people will define a dependency as compile
and will not want it packaged within a jar
?