Maven artifact and groupId naming

后端 未结 5 1764
野性不改
野性不改 2020-11-30 16:01

I\'m currently in the process of moving some project from Ant to Maven. Conformist as I am, I want to use well-established conventions for finding groupId and <

相关标签:
5条回答
  • 2020-11-30 16:32

    Your convention seems to be reasonable. If I were searching for your framework in the Maven repo, I would look for awesome-inhouse-framework-x.y.jar in com.mycompany.awesomeinhouseframework group directory. And I would find it there according to your convention.

    Two simple rules work for me:

    • reverse-domain-packages for groupId (since such are quite unique) with all the constrains regarding Java packages names
    • project name as artifactId (keeping in mind that it should be jar-name friendly i.e. not contain characters that maybe invalid for a file name or just look weird)
    0 讨论(0)
  • 2020-11-30 16:39

    However, I disagree the official definition of Guide to naming conventions on groupId, artifactId, and version which proposes the groupId must start with a reversed domain name you control.

    com means this project belongs to a company, and org means this project belongs to a social organization. These are alright, but for those strange domain like xxx.tv, xxx.uk, xxx.cn, it does not make sense to name the groupId started with "tv.","cn.", the groupId should deliver the basic information of the project rather than the domain.

    0 讨论(0)
  • 2020-11-30 16:40

    Consider following as for building basic first Maven application:

    groupId

    • com.companyname.project

    artifactId

    • project

    version

    • 0.0.1
    0 讨论(0)
  • 2020-11-30 16:41

    Consider this to get a fully unique jar file:

    • GroupID - com.companyname.project
    • ArtifactId - com-companyname-project
    • Package - com.companyname.project
    0 讨论(0)
  • 2020-11-30 16:46

    Weirdness is highly subjective, I just suggest to follow the official recommendation:

    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

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