21

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 says that artifactIDs should be

"whatever name you want with lowercase letters and no strange symbols"

but some folks in my group want to use the reverse domain name style for both groupIDs and artifactIDs.

Based on the above-mentioned guidelines plus all the examples that I've seen in the central repository I don't think it makes sense to have reverse domain style artifactIDs but I can't tell if doing so is actually invalid or merely frowned upon. I vaguely remember reading something about various repository managers not being able to deal effectively with artifactIDs that contain period (.) characters but I don't remember where I read that & I can't find it now.

What are the rules, if any, on the characters allowed in a Maven artifactID?

4
  • 1
    Comment instead of answer, but for example Eclipse artifacts use periods in the name--I haven't run across this being an issue ever, at least not for several years. Aug 17, 2012 at 23:35
  • 2
    Look at the response to this question. The guy provide regex.
    – gontard
    Aug 18, 2012 at 6:32
  • This is a really great question ! I was trying to answer by myself ... but it's too late (beer time hu hu hu :D). I will try in the next couple of days (I'm in holidays so it's may be difficult). Nevermind ... if there is no straight answer I will give a bounty for it ! It's really a great question ! Aug 18, 2012 at 17:24
  • Thanks to all for replying. I think that gontard actually had the best answer but since it was left as a comment I couldn't select it.
    – carej
    Aug 20, 2012 at 15:35

2 Answers 2

24

As a beggining here some posts dealing with this subject :

Pointers

And on Stack Overflow !

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.

4
  • 1
    When it comes to OSGi projects it seems to be a best practice to use the groupId inside of the artifactId. (Examples: aries.apache.org/development/maven-best-practice-in-aries.html, search.maven.org/…)
    – kaufholdr
    Jul 7, 2014 at 20:33
  • What's about OSGi bundles? In the Spring Enterprise Bundle Repository all bundles appears with the groupId inside of the artifactId Aug 14, 2014 at 11:56
  • That's because the Eclipse side of the OSGi alliance seem to be hell bent on bucking all conventions that they did not create for no clear benefit. Including the groupId in the artifactId is redundant. It's use in OSGi seems to have originated with bnd's early efforts to integrate with maven where the developer of said integration didn't understand or chose to ignore the established Maven naming conventions.
    – Jade
    Sep 7, 2016 at 1:53
  • 1
    commons-math has more than "lowercase letters". The inclusion list seems incomplete. Jan 18, 2017 at 6:26
4

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.

1
  • Now for the tricky part: should the uppermost package of a jar correspond to the groupId or to groupId.CLEANUP(artifactId), e.g. given groupId: org.foo, artifactId: bar-maven-plugin => package org.foo.barmavenplugin. Oct 7, 2012 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.