What is the difference between artifactId and groupId in pom.xml?
Asked Answered
J

5

52

How would you explain it to a newbie web developer or programmer with some real world organization example (like say facebook company or Google company)?

Jeramey answered 27/8, 2016 at 21:13 Comment(3)
I tried to learn it by myself, but I have hard time understanding it. I watched videos, links, few answers in SO, nothing helped. So please help me.Jeramey
Possible duplicate of Maven artifact and groupId namingCuttlebone
It is one of the most common question asked in any software engineering interview. By this question, interviewer wants to know about your basic knowledge on Maven and pom.xml file. I find recently one nice blog post on it with real life example. Just sharing the link here. Hope it will help others. Difference between groupId and artifactId in pom.xmlMaybellemayberry
A
44

From maven.apache.org, Naming Conventions:

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

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. Look at More information about package names. eg. org.apache.maven, org.apache.commons

Apology answered 27/8, 2016 at 21:17 Comment(8)
So lets say my company ABC decided to put my project in internet for public use, the artifactId:<nameOftheJar>, groupId:com.abc.www ? What happens if some one comes up with same name for artifact ID and groupId. There are some probability for that too.Jeramey
@user3705478 Hm, interesting question. You can try to create a new project using the values for a well known one, and even add it as a dependency, to explore. For example, try "creating" the Apache Commons library: mvn archetype:generate -DgroupId=org.apache.commons -DartifactId=commons-collections4 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false and then add the "real" commons library as a dependency. It appears to work fine. I'm not sure why there is not an occlusion, internally.Apology
When you say a"add it as a dependency" add it to central universal repository or to my local project?Jeramey
@user3705478 As far as a central repository, you'd have to register your groupId with the provider, and that's likely where the enforcement happens. For example, if you use Open Source Software Repository Hosting, Sonatype requires you to complete a JIRA ticket with your requested groupId.Apology
@user3705478 Here's a whole video all about it, just found this: youtube.com/watch?v=P_3yo-oU1To&feature=youtu.beApology
Thank you very much for the link. Now I understood better. And I tried creating a second maven project with same artifact ID in my local machine and maven thrown an error.Jeramey
the version tag, are the artifactId or groupId? or is the version of mix (artifactId+groupId)?Boutin
"groupId will identify your project uniquely across all projects", where? Who prevents me from having a project with the same groupid and artefactid as another person in another part of the world? This is what is missing from this answer.Irons
E
10

In case of newbie understanding. This Link describes the best understanding of project identifiers. If I narrow down to main topic then here is the point:

Maven uses a set of identifiers, also called coordinates, to uniquely identify a project and specify how the project artifact should be packaged:

  • groupId – a unique base name of the company or group that created the project
  • artifactId – a unique name of the project

If you want to understand how these identifiers have impact on POM you can visit

  1. Project Inheritance
  2. Project Aggregation
Epochmaking answered 30/12, 2020 at 6:2 Comment(0)
T
2
  • groupId uniquely identifies your project across all projects.
  • artifactId is the name of the jar without version.
Tracey answered 25/12, 2021 at 17:11 Comment(0)
R
1

In POM, or anywhere, an artifact has three things

  1. List item
  2. group id
  3. version

group id uniquely tells where it belongs, artifact id tells what it is and version tells what exact version of the artifact.

For example, androidx.activity:activity-compose:1.7.1

Syntax: groupid:atrifactid:version

This means for androidx.activity:activity-compose:1.7.1, androidx.activity is a group id, activity-compose is an artifact id, and 1.7.1 is version of artifact.

You can check this in google repo (url: https://maven.google.com/web/index.html?q=activity-compose#androidx.activity:activity-compose:1.7.1) screenshot below,

enter image description here

The link of actual artifact: https://dl.google.com/android/maven2/androidx/activity/activity-compose/1.7.1/activity-compose-1.7.1.aar

Rhapsodic answered 2/5, 2023 at 21:59 Comment(0)
C
0

The main difference between groupId and artifactId in Maven is that the groupId specifies the id of the project group while the artifactId specifies the id of the project.

It is required to use third party libraries when developing a project. The programmer can download and add these third-party libraries to the project, but it is difficult to update them later. Maven provides a solution to this issue. It helps to include all the dependencies required for the project. Moreover, the programmer can specify the required dependencies in the POM.XML file. It has the configuration information to build the project. Furthermore, this file consists of several XML elements, and two of them are groupId and artifactId. example groupId : com.test.java (similar to package name) artifactId : javaproject(project or module name)

Croatian answered 18/10, 2019 at 2:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.