Google Best Practices for Java Libraries(转载)

Google Best Practices for Java Libraries are rules that minimize problems for consumers of interconnected Java libraries. These practices come from decades of aggregated experience in maintaining open source Java libraries and are informed by many hard-learned lessons from mistakes that have been made. We have found that following these rules results in higher quality Java libraries with fewer dependency conflicts and other kinds of problems. The list is open-ended, so new ones may be added from time to time.

Best practices

  • JLBP-1: Minimize dependencies
  • JLBP-2: Minimize API surface
  • JLBP-3: Use Semantic Versioning
  • JLBP-4: Avoid dependencies on unstable libraries and features
  • JLBP-5: Avoid dependencies that overlap classes with other dependencies
  • JLBP-6: Rename artifacts and packages together
  • JLBP-7: Make breaking transitions easy
  • JLBP-8: Advance widely used functionality to a stable version
  • JLBP-9: Support the minimum Java version of your consumers
  • JLBP-10: Maintain API stability as long as needed for consumers
  • JLBP-11: Keep dependencies up to date
  • JLBP-12: Make level of support and API stability clear
  • JLBP-13: Remove references to deprecated features in dependencies at the first opportunity
  • JLBP-14: Specify a single, overridable version of each dependency
  • JLBP-15: Publish a BOM for multi-module projects
  • JLBP-16: Ensure upper version alignment of dependencies for consumers
  • JLBP-17: Coordinate rollout of breaking changes
  • JLBP-18: Only shade dependencies as a last resort
  • JLBP-19: Place each package in only one module
  • JLBP-20: Give each jar a module name

Concepts

What is a diamond dependency conflict?
Why doesn’t the compiler catch diamond dependency conflicts?


翻译:

Google Java库最佳做法是将互连的Java库的使用者的问题减至最少的规则。这些实践来自数十年来维护开源Java库的综合经验,并从许多错误的经验教训中学到了这些经验。我们发现遵循这些规则将导致Java库质量更高,依赖冲突和其他类型问题更少。该列表是开放式的,因此可能会不时添加新列表。

最佳实践

  • JLBP-1:最小化依赖
  • JLBP-2:最小化API表面
  • JLBP-3:使用语义版本控制
  • JLBP-4:避免依赖不稳定的库和功能
  • JLBP-5:避免将类与其他依赖项重叠的依赖项
  • JLBP-6:一起重命名工件和程序包
  • JLBP-7:轻松实现过渡过渡
  • JLBP-8:将广泛使用的功能提高到一个稳定的版本
  • JLBP-9:支持使用者的最低Java版本
  • JLBP-10:保持消费者需要的API稳定性
  • JLBP-11:保持依赖关系为最新
  • JLBP-12:明确支持级别和API稳定性
  • JLBP-13:第一次删除对依赖项中不推荐使用的功能的引用
  • JLBP-14:为每个依赖项指定一个可覆盖的版本
  • JLBP-15:发布多模块项目的物料清单
  • JLBP-16:确保使用者的依赖项的较高版本对齐
  • JLBP-17:协调发布重大变更
  • JLBP-18:仅将阴影依赖作为最后的手段
  • JLBP-19:将每个包装仅放在一个模块中
  • JLBP-20:给每个jar一个模块名称

概念

什么是钻石依赖冲突?
为什么编译器没有捕获菱形依赖冲突?