Linux -- Maven's use of private libraries (Nexus3)

For the construction of Maven private server, you can refer to my blog: https://my.oschina.net/u/2963821/blog/1806035

1. Description of pepositories

maven-central: maven central library, pulls jar from https://repo1.maven.org/maven2/
by default maven-releases: private library release jar
maven-snapshots: private library snapshot (debug version) jar
maven-public: Warehouse grouping, the above three warehouses are combined to provide external services, and used in the local maven basic configuration settings.xml.

Second, the use of private libraries

1. Set up a remote warehouse for a single project

Add the following information to the pom.xml file in the Maven project

<repositories> 
    <repository> 
        <id>nexus</id> 
        <name>Nexus3 Repository</name>
        <!-- 此为仓库地址 --> 
        <url>http://192.168.230.129:8081/repository/maven-public/</url> 
    </repository> 
</repositories>

Select the required warehouse urlin the path of the label in the code , click under the field to copyRepositoriesURLcopy

2. Set up remote warehouses for all projects

Modify Maven's configuration file settings.xml

2.1) Add the following information to setting.xml

<profiles>
  
    <profile> 
      <id>NexusRepo</id> 
      <repositories> 
        <repository> 
          <id>nexus</id> 
          <name>Nexus3 Repository</name> 
          <url>http://192.168.230.129:8081/repository/maven-public/</url> 
          <releases> 
            <enabled>true</enabled> 
          </releases> 
          <!-- snapshots默认是关闭的,需要手动开启 --> 
          <snapshots> 
            <enabled>true</enabled> 
          </snapshots> 
        </repository>
      </repositories> 
    </profile>

    
  </profiles>

  <activeProfiles>
    <activeProfile>NexusRepo</activeProfile>
  </activeProfiles>

Note : In this method, if the remote warehouse is closed or exits unexpectedly, it will go to the central warehouse to find the jar package when maven is built.

2.2) Add the following information to setting.xml

<mirror>
      <id>nexus-tout</id>
      <!-- *号代表所有仓库,此处也可以单独设置,以逗号隔开 -->
      <mirrorOf>*</mirrorOf>
      <name>Nexus3 tout</name>
      <url>http://192.168.230.129:8081/repository/maven-public/</url>
</mirror>

Note : This method is the same as adding an Alibaba Cloud image, and will make the configuration in 2.1) above invalid.

3. Publish the jar package

If you want to publish the jar package of the project, you can configure the following information:

  • Add the following information to the pom.xml file in the Maven project
  <distributionManagement> 
    <repository> 
      <id>maven-releases</id> 
      <name>maven releases</name> 
      <url>http://192.168.230.129:8081/repository/maven-releases/</url> 
    </repository> 
    <snapshotRepository> 
      <id>maven-snapshots</id> 
      <name>maven snapshots</name> 
      <url>http://192.168.230.129:8081/repository/maven-snapshots/</url> 
    </snapshotRepository> 
  </distributionManagement>

 

  • setting.xml add the following information
  <servers>
    <server> 
      <id>maven-releases</id> 
      <username>admin</username> 
      <password>admin123</password> 
    </server> 
    <server> 
      <id>maven-snapshots</id> 
      <username>admin</username> 
      <password>admin123</password> 
    </server> 
  </servers>

 

Note : The upper and lower ids must be the same! !

Then you can deploy, build and upload the jar package

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325318372&siteId=291194637