{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner

Maven Tip: Project Directories Should Match the Artifact ID

I almost called this post a Maven “Pet Peeve”, but I’ll stick with “Tip” (and I’ll keep it brief). Here’s a new rule, and I’d really like to hear what the community thinks about this.

Here’s the rule:

Name your project’s directory after the artifactId of your project. It is much easier for everyone to quickly recognize and comprehend multi-module project structure, and it will more closely resemble the experience for developers working with IDEs.

Why do this?

Because it leads to simpler, easier to understand project structure. Some of you might be reading this and asking why we need to remind people of such an obvious rule. Others might take issue with the proposed rule, but I’ll try to detail why I think it is so important. Take the following collection of projects as an example:

Which one do you prefer? Left or right, and why?

On the one hand it is less typing for people on the command line to use simple directory names for Maven modules.

But, on the other hand, if you import these projects with m2eclipse you are going to end up with projects named after the artifactId. The same is true if you import these projects into IntelliJ.

I would suggest always opting for the option on the right. It is clearer than the alternative, and requires less hands-on investigation to track down a culprit project if you are debugging build errors.

An Important Note from Brian Fox: Naming the folder after the artifactId is critical if you expect inherited urls (scm/site) to work. It always appends the artifactId to the url as it’s inherited. And for the same reason, you want them to match what’s in the scm.

From http://www.sonatype.com/people/2011/01/maven-tip-project-directories-and-artifact-ids/

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks