我应该如何命名我的 Java 9 模块?

How should I name my Java 9 module?

假设我有一个包含 groupId = org.abcartifactId = myLibrary 的库。模块名称的推荐名称是什么:myLibraryorg.abc.myLibrary?有官方的命名方案指南吗?

一段时间以来,对您的问题存在两种不同的意见,但在模块系统的开发过程中,社区决定采用反向 DNS 方法。

唯一模块名称 - 反向 DNS

这里假设模块名称应该是全局唯一的。鉴于该目标,实现该目标的最务实方法是遵循包命名策略并反转与维护者关联的域名。 The State of the Module System says this:

Module names, like package names, must not conflict. The recommended way to name a module is to use the reverse-domain-name pattern that has long been recommended for naming packages.

此外,Mark Reinhold writes:

Strongly recommend that all modules be named according to the reverse Internet domain-name convention. A module's name should correspond to the name of its principal exported API package, which should also follow that convention. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should at least start with the reversed form of an Internet domain with which the author is associated.

其他 Java 专家 like Stephen Colebourne.

分享的内容非常清楚

模块大于工件

有一段时间(2016 年初)还有另一项推荐。 JDK 团队声明模块名称可能不必是唯一的 "because modules are more abstract than the artifacts that define them"。 Mark Reinhold writes:

Choose module names that start with the name of your project or product. Module (and package) names that start with reversed domain names are less likely to conflict but they're unnecessarily verbose, they start with the least-important information (e.g., com, org, or net), and they don't read well after exogenous changes such as open-source donations or corporate acquisitions (e.g., com.sun.*).

The reversed domain-name approach was sensible in the early days of Java, before we had development tools sophisticated enough to help us deal with the occasional conflict. We have such tools now, so going forward the superior readability of short module and package names that start with project or product names is preferable to the onerous verbosity of those that start with reversed domain names.

此外,具有不包含域的模块名称将允许将该模块与另一个实现交换,只要它具有相同的名称(并且实现相同的 public API 当然) .

在上面的邮件中,Reinhold 记录了他的观点改变:

Some people may prefer shorter, project-oriented names, and those can be fine to use in limited projects that will never, ever see the light of day outside of a single organization. If you create a module that has even a small chance of being open-sourced in the future, however, then the safest course is to choose a reverse-DNS name for it at the start.

总结

评审团已经成立,每个发表意见的人 public 都同意像包裹一样的反向 DNS。

我想我们从 Mark Reinhold 那里得到了 "official" answer

Strongly recommend that all modules be named according to the reverse Internet domain-name convention. A module's name should correspond to the name of its principal exported API package, which should also follow that convention. If a module does not have such a package, or if for legacy reasons it must have a name that does not correspond to one of its exported packages, then its name should at least start with the reversed form of an Internet domain with which the author is associated.