What is a Maven artifact?

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

What is an artifact and why does Maven need it?

相关标签:
9条回答
  • 2020-11-29 15:16

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

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

    Artifacts live in repositories.

    0 讨论(0)
  • 2020-11-29 15:20

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题