Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 878
carej Avatar asked Aug 17 '12 21:08

carej


People also ask

What should be the artifactId in Maven?

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.

What are Maven conventions?

Maven uses Convention over Configuration, which means developers are not required to create build process themselves. Developers do not have to mention each and every configuration detail. Maven provides sensible default behavior for projects. When a Maven project is created, Maven creates default project structure.

How do you name a groupId in Maven?

The name of the groupId element has to be in lower case. Use the reverse of a domain name that can be used to uniquely identify your project. This will also help to avoid collisions between artifacts produced by different projects. Avoid using digits or special characters (that is, org.

Is Maven artifactId case sensitive?

Re: Are group/artifact IDs case sensitive to maven? no, it doesn't depend on OS.


2 Answers

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.

like image 93
Jean-Rémy Revy Avatar answered Sep 27 '22 19:09

Jean-Rémy Revy


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.

like image 22
khmarbaise Avatar answered Sep 27 '22 20:09

khmarbaise