What is a Maven artifact?

后端 未结 9 901
悲哀的现实
悲哀的现实 2020-11-29 14:20

What is an artifact and why does Maven need it?

9条回答
  •  心在旅途
    2020-11-29 15:20

    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.

提交回复
热议问题