处理可选依赖关系的最佳策略 [英] Best strategy for dealing with optional dependencies

查看:98
本文介绍了处理可选依赖关系的最佳策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从 Flyway 中删除Spring依赖关系。在未来,可能需要其他类型的依赖关系来支持用户的一部分(例如JBoss VFS支持)。

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 as JBoss VFS support).

哪个是最好的支持方式可选的依赖关系(Maven POM中的可选= true)?

Which is the best way to support optional dependencies (optional=true in Maven POM)?

解决方案的质量是:


  • 为最终用户提供易用性(如果依赖关系存在,则使用功能所需的最低工作量)

  • 开发人员使用易用性(处理可选依赖关系的代码应该尽可能简单直观)

  • 没有不必要的依赖关系(如果一些最终用户不需要这个功能,不需要拉扯依赖)

推荐答案

我认为Maven的可选依赖关系功能是非常有限的。

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

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

默认情况下,可选依赖关系不会被下拉(作为传递依赖关系)。但是,如果您的用户需要使用这些可选功能,则必须在其POM中明确声明缺少的依赖关系。

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.

我个人并不清楚这对您有帮助用户....我认为您的POM中的可选依赖项会记录您的代码所依赖的版本。然而,并不是所有的用户都会读取POM,他们会看到的是NoClassDef Found错误: - (

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 :-(

我最后的观察结果是,这是罕见的依赖关系管理器(如常春藤)的场景提供了更多的灵活性,常春藤有一个概念称为配置。模块作者可以组合不同的组合依赖关系,例如with-spring或without-spring。

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".

这篇关于处理可选依赖关系的最佳策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆