Best strategy for dealing with optional dependencies

后端 未结 2 987
面向向阳花
面向向阳花 2021-02-02 09:40

I\'m currently in the process of removing the Spring dependency from Flyway. In the future though other types of dependencies might be needed to support a subset of users (such

2条回答
  •  醉酒成梦
    2021-02-02 10:16

    I think Maven's optional dependency functionality is quite limited.

    http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

    Optional dependencies will not get pulled down (as transitive dependencies) by default. However, if your users need to use these optional features the missing dependencies must be explicitly declared, in their POM.

    Personally, it's not clear to me how this is helpful to users.... I suppose the optional dependencies in your POM do document which versions your code depends on. Not all users however will read the POM, all they'll see is the "NoClassDef Found" error :-(

    My final observation is that this is one of those rare scenarios where a dependency manager like ivy offers more flexibility. Ivy has a concept called "configurations". Module authors can assemble different combinations of dependencies, for example "with-spring" or "without-spring".

提交回复
热议问题