Chapter 3 maven core concepts - coordinates

 Let's take a look at the maven project we created with eclipse in the previous chapter



 We can see that there is a junit jar package in the Maven Dependencies library, and we create a new unit test under src/main/test, which can reference the classes in the junitjar package. This is because there is a dependency configuration in the generated pom configuration file:



 That is, maven automatically added the junit jar package for us. Let's think about a question first, maven is going to add the jar package of junit, how does it recognize that the jar package is the jar package of junit, not the jar package of spring? That is, how does it distinguish between different jar packages?

We say that we need to distinguish different points on the plane, we can use the abscissa and ordinate to represent; to distinguish different points in space, we use the three elements of x, y, and z to determine; in life, to distinguish different addresses, It can be represented by the street number of the province, city and county. So how does maven differentiate between different jar packages? The answer is coordinates.

  Just like the address is a coordinate, its elements are provinces, cities, counties, etc., and the elements of maven coordinates are mainly groupId, artifactId, version.

  groupId: The actual project to which the maven project belongs, it is required. The maven project is not necessarily one-to-one with the actual project, such as Springframework. Springframework is an actual project, but it will be divided into many projects such as spring-core and spring-bean, and each project is a maven project. The naming method of groupId is generally company or organization name + actual project name, which is similar to that of java package name;

  artifactId: the name of the maven project (module), it is also required, it is recommended to use the actual project name as a prefix, such as spring-core;

  version: the current version of the project, such as 1.0.1, it is also required;

  packaging: the project packaging method, it is optional, usually corresponds to the extension of the generated component, the default is jar

  classifier: defines the auxiliary components of the build output, such as javadoc, etc., which cannot be defined directly

Among them, groupId, artifactId, and version are required, referred to as GAV. It is through these three elements that maven distinguishes different jar packages, such as junit, and its coordinates may be as follows:

<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>

 Different versions of jar packages are reflected in different versions, such as:

<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>

We already know that maven distinguishes different jar packages by coordinates, so how does maven help me add these jars, will maven take the initiative to help us add the jar packages we need? The answer is no, maven is not so smart, I want us to tell it what jar package (dependency) we need, and then it will do the corresponding processing, which is the dependency. We will elaborate on the concept of dependencies in the next chapter.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326776861&siteId=291194637