SoFunction
Updated on 2025-03-02

About Maven

Maven Description

Questions about Maven's very basic

Maven means, many people search online, similar to the question below, in the file

<relativePath /> <!-- lookup parent from repository  --> 

What does it mean?

    <parent>
        <groupId></groupId>
        <artifactId>webbase-dependency-management</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Most of the online return to the following:

  • Setting an empty value will always be retrieved from the repository, not from the local path, such as <relativePath />
  • Maven
  • The default value is.../
  • Search order: Address in relativePath element – ​​local repository – remote repository

Some Java novices or some old birds are also confused

The first line of answer:

Setting an empty value will always be retrieved from the repository and not from the local path, such as <relativePath />

Then I started asking: Which warehouse is it? ?

I wondered what Baidu search is. Wouldn't it be enough to test it yourself? In addition, just click in and see the native instructions. The following is the native English explanation of xml:

      <xs:element name="relativePath" minOccurs="0" type="xs:string" default="../">
        <xs:annotation>
          <xs:documentation source="version">4.0.0</xs:documentation>
          <xs:documentation source="description">
            The relative path of the parent &lt;code&gt;&lt;/code&gt; file within the check out.
            The default value is &lt;code&gt;../&lt;/code&gt;.
            Maven looks for the parent pom first in the reactor of currently building projects, then in this location on
            the filesystem, then the local repository, and lastly in the remote repo.
            &lt;code&gt;relativePath&lt;/code&gt; allows you to select a different location,
            for example when your structure is flat, or deeper without an intermediate parent pom.
            However, the group ID, artifact ID and version are still required,
            and must match the file in the location given or it will revert to the repository for the POM.
            This feature is only for enhancing the development in a local checkout of that project.
          </xs:documentation>
        </xs:annotation>
      </xs:element>

Read English, but you can't translate dictionary, and then do your own experiments to draw the following conclusion:

  1. relativePath is an additional search path that Maven adds to find the parent module
  2. The default value of relativePath is …/

Maven finds the order of parent modules

as follows:

(1)  first in the reactor of currently building projects

Here is a maven concept reactor, which means first looking for the parent you introduced from the relevant modules in the project.

(2) then in this location on the filesystem

Then look for the <relativePath> path you defined. Of course, if you are just /, that is, empty, then skip this step. The default value ../ is found from the previous directory.

(3)  then the local repository

I won’t talk about this. If (1) (2) If there is no step, I will look for it from the local warehouse.

(4) and lastly in the remote repo

Is this something more important? It can’t be found above, so I can only look for it from the remote warehouse. If I can’t find it, I will report an error to you.

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.