2010/9/23 Max Bowsher <[email protected]>:
> It seems to me that in a Maven dependency, <scope>provided</scope> and
> <optional>true</optional> have incredibly similar semantics (though
> there is an implied difference in meaning to humans).

scope=provided means that the library is needed for compilation and
runtime, however it is provided by some sort of container. Typical
example: servlet-api
optional=true means that a library is needed for compilation, but it
is not necessary at runtime. Very often this is a symptom of poorly
made modules: it is best to isolate optional code into a different
module where the dependency is not an option. For example, in Velocity
Tools we had an optional dependency on an XML library, for a specific
XML tool. Isolating this code into a new module made this dependency
mandatory, but you have to include one more module in the using
project.
A well-done use case of an optional dependency (IMO) is a dependency
on a library where exists several alternatives. For example, with
SLF4J you specify a mandatory dependency (slf4j-api) and an optional
dependency (e.g. slf4j-jdk14). However there are several alternatives
with the same basic code, for example slf4j-log4j12, slf4j-logback...

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to