Best practices in naming conventions on Maven artifactID (is there restriction?)

后端 未结 2 1338
遇见更好的自我
遇见更好的自我 2021-01-31 10:47

My team is new to Maven and we haven\'t been able to find any definitive guidance on selecting artifactIDs for our projects.

I know that the Guide to naming conventions

相关标签:
2条回答
  • 2021-01-31 10:57

    As a beggining here some posts dealing with this subject :

    Pointers

    • using groupId in artifactId is now deprecated
    • sonatype trustable conventions

    And on Stack Overflow !

    • Naming convention for Maven Artifacts

    Then, I would suggest you to NOT use groupId in you artifactId. This is redundant ;).

    I quote the sonatype docs that seems to be the most relevant for your question :

    Sonatype Naming Conventions

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

    So using reverse dns in you groupId AND your package name is a good pratice. Use them again in artifactId is not.

    0 讨论(0)
  • 2021-01-31 11:19

    I would argument that the groupId is like the package name in Java where the artifactId is similar to the class name (ok not really) but I think there is a relationship to the class name. In Maven you usually give a name to a module/project which is in particular the artifactId.

    Furthermore I found some hints about the artifactId here.

    0 讨论(0)
提交回复
热议问题