java 9 个模块的命名约定

Naming convention for java 9 modules

java 9 个模块的命名约定是什么?假设我的包名是 me.jasonyeo.awesome.project,每当我在 IDEA 中创建一个 module-info.java 文件时,它会建议我将它命名为 awesome.project

这是惯例吗?或者我应该将其命名为 me.jasonyeo.awesome.project?

看来,IDEA 的建议是基于 Java 的内置模块有两个组件,例如java.basejava.desktop,但这对第 3 方模块来说并不是一个好的建议。

JLS §6.1, Declarations 说:

The name of a module should correspond to the name of its principal exported package. 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 still start with the reversed form of an Internet domain with which its author is associated.

Example 6.1-2. Unique Module Names

com.nighthacks.scrabble
org.openjdk.compiler
net.jcip.annotations

您可以使用 direct link to the example

更快地找到引用的部分

所以你的假设是正确的,推荐的模块名称是me.jasonyeo.awesome.project,而不是awesome.project