Maven (2)-coordinate and dependency, maven coordinate dependency

Source: Internet
Author: User

Maven (2)-coordinate and dependency, maven coordinate dependency

This article briefly introduces the coordinates (coodinate) and Dependency management (Dependency) in Maven)

I. Coordinates

First:

In the peoject column, there are groupId, artifactId, and version. This is the concept of coordinates in maven. These three attributes can uniquely locate a java shelf package, where:

  • GroupId indicates the organization of the Rack package (the concept of package), such as com. cnblogs
  • ArtifactId is the unique expression of a separate rack package (project ).
  • Version indicates the version number of the current project.

In addition, the coordinates also have a packaging attribute, which represents the project type. The default value is jar, which describes the output after the project is packaged.

  • A project of the jar Type generatesJAR File
  • A war project generates a web application.

In a maven project, groupId, artifactId, and version represent the coordinates of a project. Other projects can use the unique units of these coordinate attributes to the current project.

The unique coordinates of junit can be reserved to junit4.12 and used in the project.

Maven repository uses these coordinates to organize maven projects. After the project specifies the dependent coordinates, the project can find the corresponding maven project from the maven remote repository, when the maven project with the corresponding coordinates is already in the local repository, the project will automatically use the project that can match the local repository coordinates without downloading it from the remote repository.

Ii. Dependency Management

Maven coordinates are the core of maven projects, and dependencies are internship through maven coordinates. The preceding example demonstrates the dependency in maven: the Dependency option is added to the pom file. The Dependency option directly displays the coordinates of the project on which the project depends.

2.1 transmission dependency

In, the current project depends on Project B and Project c, Project B depends on project d, and Project c depends on Project e. In maven, for the current project, you only need to pay attention to B and c. That is to say, in the pom file of the current project a, you only need to configure the dependencies on B and c. The passing dependency of d and e is automatically loaded by maven, without the attention of the current project, this is one of the most powerful maven tools (able to manage dependencies well)

2.2 dependency Scope

    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.12</version>        <scope>test</scope>    </dependency>

In the preceding dependency configuration, a scope option is added, and the scope option specifies the scope for the maven dependency to take effect. The scope of the preceding example is test, it indicates that the Compiler plug-in is unavailable when running the compile target. It is added to classpath only when the compiler: testCompile and surefire: test targets are run.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.