Reputation: 86687
I'm writing some kind of framework, and within want to provide a specific feature that uses lucene
(take lucene as an example of any feature here).
So in my framework I definitely have to maven
include the lucene library as dependency
to be able to build the feature upon.
Now I don't want to create a submodule for every feature, but rather have everything packed in a single jar library. And if the user wants to use the lucene-feature, he might activate it using Spring
, and would also have to include the lucene libs with maven.
But how can I achive this? So far I have the lucene library in my framework, and if I use this as a dependency, automatically the lucene libs are imported too, even if the feature is not used. How can I prevent this?
Upvotes: 1
Views: 1483
Reputation: 371
I guess the Maven scope provided
would solve your problem :
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>4.10.0</version>
<scope>provided</scope>
</dependency>
From the maven documentation :
- compile
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.
- provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
In your case you do not expect a container to provide the dependency but the user of your framework to include it (if he needs to).
Upvotes: 3