我目前正在把一些项目从Ant转移到Maven。我是一个墨守成规的人,我想使用完善的约定来查找groupId和artifactId,但我找不到任何详细的约定(有一些,但它们不包括我想知道的要点)。

以这个项目为例,首先是Java包:com.mycompany.teatimer

Tea timer实际上是两个单词,但是Java包命名约定禁止插入下划线或连字符,所以我把它们写在一起。

我选择了与包ID相同的groupId,因为我认为这是一个好主意。是吗?

最后,我必须选择一个artifactId,我目前去了teatimer。但是当我查看其他Maven项目时,它们使用连字符分隔artifactid中的单词,例如:tea-timer。但是当连接到groupId: com.mycompany.teatimer.tea timer时,它看起来确实很奇怪。

你会怎么做呢?

另一个例子:

包名:com.mycompany.awesomeinhouseframework

groupId: com.mycompany.awesomeinhouseframework ?

artifactId: awesome-in - house-framework (?)


当前回答

奇怪与否是非常主观的,我只是建议遵循官方的建议:

Guide to naming conventions on groupId, artifactId and version groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names. eg. org.apache.maven, org.apache.commons A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId. eg. org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting artifactId is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar you have to take the name of the jar as it's distributed. eg. maven, commons-math version if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look. eg. 2.0, 2.0.1, 1.3.1

其他回答

但是,我不同意关于groupId、artifactId和version的官方命名规范指南的定义,该指南建议groupId必须以您控制的反向域名开始。

Com表示该项目属于公司,org表示该项目属于社会组织。这些都是可以的,但是对于那些奇怪的域,比如xxx。电视,xxx。如果以“tv.”,“cn.”开头,groupId的名称是没有意义的,groupId应该提供项目的基本信息,而不是域名。

考虑以下构建基本的第一个Maven应用程序:

groupId

com.companyname

artifactId

项目

版本

0.0.1

你的惯例似乎是合理的。如果我在Maven repo中搜索您的框架,我会在com.mycompany.awesomeinhouseframework组目录中查找awome-inhouse-frame-x.y.jar。根据你们的惯例,我可以在这里找到它。

两个简单的规则对我很有用:

groupId的reverse-domain-packages(因为这是非常独特的),以及所有关于Java包名称的约束 项目名称为artifactId(请记住,它应该是jar-name友好的,即不包含可能无效的文件名或只是看起来奇怪的字符)

奇怪与否是非常主观的,我只是建议遵循官方的建议:

Guide to naming conventions on groupId, artifactId and version groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names. eg. org.apache.maven, org.apache.commons A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId. eg. org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting artifactId is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar you have to take the name of the jar as it's distributed. eg. maven, commons-math version if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look. eg. 2.0, 2.0.1, 1.3.1