maven私服的配置何使用

maven私服介绍

maven私服它是一种远程仓库,他能够节省自己的外网宽带,加速maven构建,部署自己内部的第三方构建,提高稳定性等

当Maven需要下载构件的时候,它从私服请求,如果 私服上不存在该构件,则从外部远程仓库下载,缓存在私服上之后,再为Maven的下载请求提供服务。

我们配置好了maven私服之后就可以开始使用了

maven仓库的类型

hosted 类型的仓库,内部项目的发布仓库

releases 内部的模块中release模块的发布仓库

snapshots 发布内部的SNAPSHOT模块的仓库

3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去

proxy 类型的仓库,从远程中央仓库中寻找数据的仓库

group 类型的仓库,组仓库用来为了方便我们开发人员而进行设置的仓库

配置

然后我们可以在本地配置的maven里配置maven私服,我们在我们本地的maven私服的settings中进行配置

在servers中配置server

       <server>
         	<!--自己定义--发布版本-->
            <id>nexus-releases</id>
            <!-- maven私服的账号密码-->
            <username>xxxx</username>
            <password>xxxxxx</password>
        </server>
		<!--快照版本 -->
        <server>
            <id>nexus-snapshots</id>
            <username>xxxxx</username>
            <password>xxxxx</password>
        </server>

又在profiles中配置仓库的地址

 <profile>
      <!--自己定义 -->
      <id>dapao</id>
	    <activation>    
		<activeByDefault>false</activeByDefault>    
		<jdk>1.8</jdk>    
      </activation>    
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
           <!--自己定义在repositories中id不能相同 -->
          <id>nexus</id>
                <!--配置仓库组地址 -->
          <url>http://xxx:8080/repository/maven-public/</url>
		  <!-- 是否把他当作发布版本或者发布库-->
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
	    <!-- 插件库跟上面一样-->
      <pluginRepositories>
        <pluginRepository>
          <id>nexus</id>
          <url>http://xxx:8080/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>

然后我们可以启用这个配置

     <activeProfiles>
     <!-- profile中的id-- >
       <activeProfile>dapao</activeProfile>
    </activeProfiles> 

我们就可以在我们项目中的pom.xml文件中

 <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>maven-releases</name>
          发布仓库的地址
            <url>xxxx/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>maven-snapshots</name>
          快照仓库的地址
            <url>xxxxxx</url>
        </snapshotRepository>
    </distributionManagement>

 <build>
        <!-- <plugins>
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
         </plugins>-->
        <plugins>
            <!--发布代码Jar插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <!--发布源码插件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

这样就可以把我的项目上传到maven私服了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值