maven项目私服使用

1.maven私服安装
https://blog.csdn.net/u012385217/article/details/51352104
安装后,maven私服仓库和本地仓库默认是空的,只有当maven项目中的pom.xml或者setting.xml中配置私服地址,就会下载到私服仓库和本地仓库中。
maven私服的作用是:需要的架包从maven官方仓库下载 到私服仓库(具体是中央仓库的id为central)和本地仓库中。
2.maven仓库介绍
maven仓库默认登陆用户名和密码是  admin/admin123 
     登陆后可以上传第三方架包(详情请看maven私服安装)
介绍仓库三种类型:
hosted,本地代理仓库,通常我们会部署自己的构件到这一类型的仓库。 
proxy,代理的远程仓库,它们被用来代理远程的公共仓库,如maven中央仓库。 
group,仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组

3.maven项目配置私服地址
一般采用有两种配置方法:
1.项目pom.xml中配置私服地址仅对当前项目有效,但若需在其他项目中使用,为避免代码重复性,减少冗余,可在settings.xml文件中配置
(小案例:如果有多个项目,但是多个项目都在一个头部maven项目下,可以将这种私服配置到顶部pom.xml中,可以避免配置代码重复)
pom文件中配置私服仓库:

<repositories>
   <!--  配置nexus远程仓库 -->
   <repository>
      <id>nexus</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
      <releases>
         <enabled>true</enabled>
      </releases>
      <snapshots>
         <enabled>true</enabled>
      </snapshots>
   </repository>
</repositories>


<!--  配置从那个仓库下载jar架包 -->
<pluginRepositories>
   <pluginRepository>
      <id>nexus</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
      <releases>
         <enabled>true</enabled>
      </releases>
      <snapshots>
         <enabled>true</enabled>
      </snapshots>
   </pluginRepository>
</pluginRepositories>
  // 当上述配置中将releases和snapshots设置true那么需要配置以下内容maven中的仓库分为两种,snapshot快照仓库和release发布仓库。snapshot快照仓库用于保存开发过程中的不稳定版本,release正式仓库则是用来保存稳定的发行版本。定义一个组件/模块为快照版本,只需要在pom文件中在该模块的版本号后加上-SNAPSHOT即可(注意这里必须是大写)
     <distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>releases</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
</repository>
  </distributionManagement>

2.setting.xml中配置私服地址
第一步配置仓库:
<profiles>
  
  <profile>
      <id>development</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
 
  </profiles>
第二步:激活profile(其中上面id和activeProfile相同)
 <activeProfiles>
    <activeProfile>development</activeProfile>
  </activeProfiles>
第三步:配置镜像mirror
 <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Nexus Mirror</name>
      <url>http://127.0.0.1:8081/content/groups/public/</url>
    </mirror>
  </mirrors>
第四步:添加用户配置(用户名和密码)
 <servers>
    <server>
      <id>development</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
<server>
      <id>Snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>

//具体可以查看该博客:https://blog.csdn.net/hh12211221/article/details/74217892

猜你喜欢

转载自blog.csdn.net/qq_39291929/article/details/80959341