Issue
Since runtime scope for maven dependency makes it impossible to "see" this dependency from parent project, how can it be useful?
Example parent maven project pom:
...
<dependency>
<groupId>org.example</groupId>
<artifactId>example-dependency</artifactId>
<version>1.0</version>
<scope>runtime</scope?
</dependency>
...
As i understand, not main
entry function, nor any classes in parent project can reference anything in example-dependency
.
According to the documentation:
This scope indicates that the dependency is not required for compilation, but is for execution. Maven includes a dependency with this scope in the runtime and test classpaths, but not the compile classpath.
But this doesn't explain exactly, how such scope can be useful. Can something somehow be executed inside such bundled dependency on it's own, without being referenced by the parent app?
What is the point of bundling such dependency into the jar?
Solution
When you know there will be an implementation at runtime environment, you don't want to refer any specific Class
of any implementation at development environment, runtime
scope could help.
As i understant, the api can have some generic classes, implementation can extend them and then what? The root app doesn't see those extending classes anyway
Java SPI (Service Provider Interface) could scan implementations in your environment (classpath) dynamically and easilly. Database drivers are common examples. (java.sql.Driver
-> MySQL / Postgres / any database driver)
Answered By - Firok
Answer Checked By - Senaida (JavaFixing Volunteer)