私服介绍:

hosted:本地存储。像官方仓库一样提供本地私库功能

proxy:提供代理其它仓库的类型

group:组类型,能够组合多个仓库为一个地址提供服务

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar

maven-releases:私库打包发行版jar

maven-snapshots:私库快照(调试版本)jar

maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 中使用。

Hosted有三种方式:Releases、Snapshot、Mixed

Releases:一般是已经发布的Jar包

Snapshot:未发布的版本

Mixed:混合的

image.png

maven的配置:

<mirrors>
	<!--
	如果想让nexus作为maven的代理仓库就不要配置这一段了
	<mirror>
		<id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
	-->
	<!-- 与上面的配置二选一,mirrorOf 为 * 表示这个镜像将替代所有的远程仓库请求 -->
	<mirror>
		<id>nexus</id>
		<mirrorOf>*</mirrorOf>
		<url>http://192.168.0.62:8081/repository/maven-central/</url>
	</mirror>
</mirrors>

配置示例:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <localRepository>/usr/local/maven/repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
    <server>
        <id>maven-releases</id>
        <username>admin</username>
        <password>admin</password>
    </server>
    <server>
        <id>maven-snapshots</id>
        <username>admin</username>
        <password>admin</password>
    </server>
  </servers>
 
  <mirrors>
    <mirror>
        <id>maven-public</id>
        <mirrorOf>*</mirrorOf>
        <url>http://192.168.0.62:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
 
  <profiles>
      <profile>
        <id>my-profile</id>
        <properties>
          <maven.compiler.source>1.8</maven.compiler.source>  
          <maven.compiler.target>1.8</maven.compiler.target>  
          <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
        <repositories>
          <repository>
            <id>maven-central</id>
            <url>http://192.168.0.62:8081/repository/maven-central/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
          </repository>
 
          <repository>
            <id>maven-releases</id>
            <url>http://192.168.0.62:8081/repository/maven-releases/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
          </repository>
 
          <repository>
            <id>maven-snapshots</id>
            <url>http://192.168.0.62:8081/repository/maven-snapshots/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
          </repository>
      </repositories>
 
    <pluginRepositories>
      <pluginRepository>
        <id>maven-public</id>
        <url>http://192.168.0.62:8081/repository/maven-public</url>
      </pluginRepository>
    </pluginRepositories>
    
    </profile>
  </profiles>
  
  <activeProfiles>
   <activeProfile>my-profile</activeProfile>
  </activeProfiles>
</settings>

配置参考:

blog.csdn.net/weixin_42599091/article/details/124981288
blog.csdn.net/wc1695040842/article/details/102575686

nexus的配置:修改 maven-central 仓库中的如下配置

image.png

image.png

创建仓库组代理多个厂库:

image.png

image.png

代理仓库需要用户名密码时可在如下位置填写:

image.png