shylynx
shylynx

Reputation: 615

Maven GroupId with special characters

One best practice for choosing the Maven groupId says to choose the groupId according to the domain name of the company. Some domain names contain special characters, especially hyphen-minus. And moreover with the new non-ASCII-domains a domain name can also contain non-ASCII-characters.

Now my questions:

  1. Can I use the minus in the groupId? What are reasonable alternatives?

  2. How do I handle special characters of non-ASCII domain names in the groupId?

  3. A concrete problem: I have to find groupIds for three independent companies: Company A's domain is "heccare.de" Company B's domain is "heccare-international.de" Company C's domain is "heccare-int.de"

What are reasonable groupIds?

Upvotes: 5

Views: 2630

Answers (2)

Fried Brice
Fried Brice

Reputation: 780

Per Oracle's documentation on package naming, hyphens (namely, -) in DNS names should be replaced with underscores (namely, _), names that begin with a number should be pre-underscored (so me.123.com becomes com._123.me), and names that conflict with a reserved keyword should be post-underscored (so int.me.com becomes com.me.int_).

Unicode characters are fine, as per the spec for identifiers (for instance, Character.isJavaIdentifierStart('é') evaluates to true).

Your group names would canonically be de.heccare, de.heccare_international, and de.heccare_int, respectively.

Upvotes: 5

Using your domain name as a groupID is not a bad idea, but it's not necessary. JUnit's groupID is simply "junit":

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

I've seen other groupIDs that are a combination of domain name, and something more descriptive, such as com.mycompany.webapi, com.mycompany.wslib, com.mycompany.database.util etc... of course, the only thing that resolves to an actual domain is mycompany.com but I don't think that's a problem.

And as for special characters, the dash is OK (just noticed that I have a dependency on Apache Commons I/O, whose groupID is "commons-io") , but non-ASCII characters, you'll just have to try and see!

Upvotes: 3

Related Questions