What is an artifact and why does Maven need it?
To maven, the build process is arranged as a set of artifacts. Artifacts include:
Artifacts live in repositories.
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.
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
.