ChatGPT解决这个技术问题 Extra ChatGPT

What is a Maven artifact?

What is an artifact and why does Maven need it?

More about Maven concepts here: tshikatshikaaa.blogspot.nl/2012/05/…
btw You can see the official Apache Maven glossary for the definition of an Artifact
None of these answers is complete. You can see this just by browsing a Maven repository. An artifact is apparently a directory satisfying some constraints, e.g. it must contain a file called maven-metadata.xml and a file called <artifactId>-<version>.pom. Both of those files have some undocumented schema and semantics.

S
Stuart Sierra

An artifact is a file, usually a JAR, that gets deployed to a Maven repository.

A Maven build produces one or more artifacts, such as a compiled JAR and a "sources" JAR.

Each artifact has a group ID (usually a reversed domain name, like com.example.foo), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact.

A project's dependencies are specified as artifacts.


Is an artifact basically a JAR file ? So, the joda time jar file can be called a joda artifact, hibernate jar can be called hibernate artifact etc ?
Think of what an artifact really is. The Egyptians created wonderful artifacts such as pottery. But, if you were holding an Egyptian bowl in your hand, you wouldn't refer to it as an "artifact" unless you were discussing the fact that it IS an artifact (fact). You would refer to it as a bowl. They ate out of the bowl. They didn't eat out of the artifact.
I think what @cbmeeks is getting at is that "artifact" is not a name for a "thing", it is a role in the build process. Anything can be classified as an "artifact" if Maven produces it and it is given special Maven coordinates to identify it.
If I have something called "com.example:mylibrary:1.0.0" (groupId:artifactId:version), that consists of a jar, a pom, and a source jar, which of the following is an artifact: 1. each file (pom, jar, source jar) is a separate artifact; 2. the set of files that share the same (groupId:artifactId:version) make up a single artifact; 3. something else?
There isn't necessarily any relationship between groupId/artifactId and class names. Often, the groupId/artifactId will match the Java package. For example, a class named com.example.myproject.MyClass might be found in groupId com.example and artifactId myproject, but this is only a convention. Maven itself does not enforce this convention. Some repositories, such as Maven Central, enforce it for new projects.
K
Ken Liu

In general software terms, an "artifact" is something produced by the software development process, whether it be software related documentation or an executable file.

In Maven terminology, the artifact is the resulting output of the maven build, generally a jar or war or other executable file. Artifacts in maven are identified by a coordinate system of groupId, artifactId, and version. Maven uses the groupId, artifactId, and version to identify dependencies (usually other jar files) needed to build and run your code.


My book says "the core artifact of this online application will be a Java class named User, which will"... Is this the same as the artifact you mentioned ?
@davidblaine - not exactly, that sentence uses the word a more general sense.
c
carlspring

I know this is an ancient thread but I wanted to add a few nuances.

There are Maven artifacts, repository manager artifacts and then there are Maven Artifacts.

A Maven artifact is just as other commenters/responders say: it is a thing that is spat out by building a Maven project. That could be a .jar file, or a .war file, or a .zip file, or a .dll, or what have you.

A repository manager artifact is a thing that is, well, managed by a repository manager. A repository manager is basically a highly performant naming service for software executables and libraries. A repository manager doesn't care where its artifacts come from (maybe they came from a Maven build, or a local file, or an Ant build, or a by-hand compilation...).

A Maven Artifact is a Java class that represents the kind of "name" that gets dereferenced by a repository manager into a repository manager artifact. When used in this sense, an Artifact is just a glorified name made up of such parts as groupId, artifactId, version, scope, classifier and so on.

To put it all together:

Your Maven project probably depends on several Artifacts by way of its elements.

Maven interacts with a repository manager to resolve those Artifacts into files by instructing the repository manager to send it some repository manager artifacts that correspond to the internal Artifacts.

Finally, after resolution, Maven builds your project and produces a Maven artifact. You may choose to "turn this into" a repository manager artifact by, in turn, using whatever tool you like, sending it to the repository manager with enough coordinating information that other people can find it when they ask the repository manager for it.

Hope that helps.


+1 for new info on old thread thanks! Fix typo "repoository" though at times poo might be the right word haha ... everyone is saying the "artifact" is the actual jar, might be helpful to update your answer to point out that when using, for example, mvn install, people are trying to figure out what to put in that entry. So the full name of the jar is what to enter for -DartifactId=YOUR_ARTIFACT_ID, is that right? The full jar file name with version and .jar? Seems to be what you're saying but would help some to be really explicit. Other answers get close to this but I thought yours best.
a
alex

Maven organizes its build in projects.

An artifact in maven is a resource generated by a maven project. Each maven project can have exactly one artifact like a jar, war, ear, etc.
The project's configuration file "pom.xml" describes how the artifact is build, how unit tests are run, etc. Commonly a software project build with maven consists of many maven-projects that build artifacts (e.g. jars) that constitute the product.
E.g.

Root-Project   // produces no artifact, simply triggers the build of the other projects
  App-Project  // The application, that uses the libraries
  Lib1-Project // A project that creates a library (jar)
  Lib2-Project // Another library
  Doc-Project  // A project that generates the user documentation from some resources

Maven artifacts are not limited to java resources. You can generate whatever resource you need. E.g. documentation, project-site, zip-archives, native-libraries, etc.

Each maven project has a unique identifier consiting of [groupId, artifactId, version]. When a maven project requires resources of another project a dependency is configured in it's pom.xml using the above-mentioned identifier. Maven then automatically resolves the dependencies when a build is triggered. The artifacts of the required projects are then loaded either from the local repository, which is a simple directory in your user's home, or from other (remote) repositories specified in you pom.xml.


T
TofuBeer

Q. What is Artifact in maven? ANS: ARTIFACT is a JAR,(WAR or EAR), but it could be also something else. Each artifact has,

a group ID (like com.your.package),

an artifact ID (just a name), and

a version string. The three together uniquely identify the artifact.

Q.Why does Maven need them? Ans: Maven is used to make them available for our applications.


Nice answer, as I commented on other answer, make it explicit what we are supposed to type into -DartifactId=YOUR_ARTIFACT_ID when running mvn install, just a suggestion :)
@JimLohse thanks, please feel free to add with "edit" title :)
d
duffymo

An artifact is a JAR or something that you store in a repository. Maven gets them out and builds your code.


b
bmargulies

To maven, the build process is arranged as a set of artifacts. Artifacts include:

The plugins that make up Maven itself. Dependencies that your code depends on. Anything that your build produces that can, in turn be consumed by something else.

Artifacts live in repositories.


V
Venky Vungarala

usually we talking Maven Terminology about Group Id , Artifact Id and Snapshot Version

Group Id:identity of the group of the project Artifact Id:identity of the project Snapshot version:the version used by the project.

Artifact is nothing but some resulting file like Jar, War, Ear....

simply says Artifacts are nothing but packages.


t
tagus

Usually, when you create a Java project you want to use functionalities made in another Java projects. For example, if your project wants to send one email you dont need to create all the necessary code for doing that. You can bring a java library that does the most part of the work. Maven is a building tool that will help you in several tasks. One of those tasks is to bring these external dependencies or artifacts to your project in an automatic way ( only with some configuration in a XML file ). Of course Maven has more details but, for your question this is enough. And, of course too, Maven can build your project as an artifact (usually a jar file ) that can be used or imported in other projects.

This website has several articles talking about Maven :

https://connected2know.com/programming/what-is-maven/

https://connected2know.com/programming/maven-configuration/


F
Faseela Thayattuchira

What is Artifact: it is a war file which contains the following three things.

Group Id: It is like com.yourCompanyName

Artifact ID: just a name

Version: a version string.

The three together uniquely identify the artifact.

Maven is used to making them available for our application. Package is usually GroupId + ArtifactId