Sub topic 4
Naming Artifacts: groupId, artifactId, and version
In the last chapter you built app.jar by hand. The name app.jar works on your own computer. But thousands of projects share code with each other, and many of them could pick the same name. Build tools need a way to tell every project apart.
An artifact is a file that a build produces, such as a JAR file. Maven and Gradle give each artifact a three-part name called its coordinates.
The three parts
| Part | What it means | Example |
|---|---|---|
| groupId | The group or company that owns the project | `com.example` |
| artifactId | The name of this one project | `hello` |
| version | Which release of the project this is | `1.0-SNAPSHOT` |
The groupId usually looks like a website address written backwards, so example.com becomes com.example. You own your domain name, so no one else is likely to use the same groupId. It often matches your Java package name.
The artifactId names the project inside the group. One group can have many projects, such as hello, core, and app.
The version tells releases apart. 1.0, 1.1, and 2.0 are different releases of the same project.
Writing coordinates
In Maven, coordinates go near the top of the project file. You will build the full file in the next chapter.
<groupId>com.example</groupId>
<artifactId>hello</artifactId>
<version>1.0-SNAPSHOT</version>In Gradle, and in many guides online, the same coordinates are often written on one line with colons between the parts:
com.example:hello:1.0-SNAPSHOTHere is a real library written the same way. Guava is a popular library from Google:
com.google.guava:guava:33.2.1-jreRelease versions and SNAPSHOT versions
A release version, such as 1.0, is final. Once it is published, its contents never change.
A SNAPSHOT version, such as 1.0-SNAPSHOT, means "work in progress toward 1.0." Its contents can change each time you build. New projects start with a SNAPSHOT version. When the code is ready, you remove -SNAPSHOT and publish a release.
Where coordinates show up
Coordinates also decide where files are stored. The build tool keeps downloaded artifacts in a folder on your computer, and the folder path comes from the coordinates. The dots in the groupId become folders:
~/.m2/repository/com/example/hello/1.0-SNAPSHOT/hello-1.0-SNAPSHOT.jarThe file name is the artifactId and the version joined by a dash. A later chapter covers this storage folder in more detail.
Exercise
A company owns the domain shop.acme.org. It is building a project called payments and is working toward its first release, 1.0. Write the coordinates in the one-line colon form.
Show answer
org.acme.shop:payments:1.0-SNAPSHOT. The domain is reversed to form the groupId, the project name is the artifactId, and -SNAPSHOT marks the work in progress toward 1.0.
Exercise
What JAR file name would a build produce for the coordinates com.google.guava:guava:33.2.1-jre?
Show answer
guava-33.2.1-jre.jar. The file name is the artifactId and the version joined by a dash.