Maven主题(三)------Maven私服安装 nexus-3.9.0-01

一、下载  nexus-3.9.0-01-win64

  链接:https://pan.baidu.com/s/1MXdfYX8Ot4S0pt4g_26j1A
      提取码:bq03

      

二、安装

  2.1 进入到bin目录,运行命令行cmd并回车(注意:需要管理员身份)

      

      

    2.2 注册服务为windows的服务并进行安装 

            nexus /install Nexus3

      

    2.3查看服务 开始-->运行-->services.msc

      

  2.4 安装成功,访问界面(第一次加载较慢)

      http://127.0.0.1:8081
        用户名 admin
        密码  admin123

3.简单介绍

  注意:更改配置如果没出现,可以F5刷新一下

  maven-release  发行版,以后我们自己编写的包发正式版就在这里
  maven-snapshots 快照包,以后我们自己推的快照包就在这里
  maven-central:是中央仓库,当我们没有依赖的时候,会去中央仓库下载,中央仓库默认地址为:https://repo1.maven.org/maven2/  我们可以改为阿里云的地址,也可以自己新建一个仓库作为中央仓库,并指定阿里  

                                 云为中央仓库
  maven-public:仓库类型为group,意思是说,它可以包含多个仓库,比如,我们可以把快照的仓库,正式包仓库,中央包仓库都放到maven-public这个组里面,然后在maven的settings里面,指定这个组的地址为我们

                             的仓库地址,这样就可以最少的配置,同时使用多个仓库了

  仓库名

      1.central:中央仓库
      2.3rd party:第三方仓库,比如,手工上传的jar包就报错在这里
      3.apache snapshots:Apache快照仓库
      4.releases:发型版本仓库
      5.Google Code:谷歌发型版本仓库
      6.public Repositories:仓库组,是上述所有仓库的聚合,对外提供统一的地址服务

  仓库类型

      1.group(仓库组):比如 public Repositories
      2.hosted(宿主):比如:releases 3rd party  本地的jar
      3.proxy(代理): 比如: central、apache snapshots

4.新建代理仓库

      

      

    

    

5.仓库组配置

    注:1.仓库组是多个仓库的集合,我们可以指定一个仓库组包含多个仓库,如仓库A,仓库B,仓库C,让maven客户端指向仓库组的地址就可以使用ABC三个仓库完成jar包的下载了

    

    

    注意:下图中右侧仓库的顺序有优先级,从上至下,比如,客户端连接到此仓库组地址时,如果maven-central在最上层,则优先从maven-central下载

      下图中的下载顺序为---maven-release,如果没有jar,则snapshots,如果没有,则查找husheng-repository(阿里云的地址),如果没有,查找maven-central仓库(默认的中央仓库地址)

    

6.Settings.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
  <localRepository>D:\software\apache-maven-3.3.9\repository</localRepository>
 

  <mirrors>
 
     <mirror>
     <id>alimaven</id>
     <mirrorOf>central</mirrorOf>
     <url>http://127.0.0.1:8081/repository/maven-public/</url>
     </mirror>
  </mirrors>


<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus</name>
                <url>http://127.0.0.1:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        
        <pluginRepositories>
            <id>nexus</id>
            <name>Nexus</name>
            <url>http://127.0.0.1:8081/repository/maven-public/</url>
               <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepositories>
    </profile>
</profiles>    

    <activeProfiles>
        <activeProfiles>
            <activeProfile>nexus</activeProfile>
        </activeProfiles>
    </activeProfiles>
    
      <servers>
      
        <server>
            <id>snapshots</id>
            <username>husheng</username>
            <password>husheng</password>
        </server>
        <server>
            <id>release</id>
            <username>husheng</username>
            <password>husheng</password>
        </server>
    
 
  </servers>
</settings>

说明:

  下载配置:

    1.如果只是下载,配置好 <localRepository>D:\software\apache-maven-3.3.9\repository</localRepository>  本地仓库的地址,也就是下载存放的目录

    2.配置好  <mirrors>,指向仓库组的地址

    3.  <mirrorOf>central</mirrorOf> 注意,这里是central

  上传配置:

    1.上传需要有用户名和密码,这个用户名和密码必须要有权限,可以使用用户名:deployment  密码:deployment123  或者创建新的用户名-->赋予角色-->角色赋权限

    2. 注意id nexus ,要和activeProfiles 激活配置的id保持一致

    3.server字段中的 <id>snapshots</id> <id>release</id>  这两个id是为了和idea中pom文件匹配的

  

7.IDEA配置

  <!-- Source attach plugin -->
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>${maven.compiler.source}</source>
            <target>${maven.compiler.target}</target>
            <encoding>${project.build.sourceEncoding}</encoding>
          </configuration>
        </plugin>

      <plugin>
        <artifactId>maven-source-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <id>attach-sources</id>
              <goals>
                <goal>jar</goal>
              </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
    </build>

<!-- 配置远程发布到私服,mvn deploy -->

      <distributionManagement>
        <!-- 快照版仓库 -->
          <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
          </snapshotRepository>
        <!-- 发行版仓库 -->
          <repository>
            <id>release</id>
            <name>Nexus Release Repository</name>
            <url>http://127.0.0.1:8081/repository/maven-releases/</url>
          </repository>
      </distributionManagement>

  注意:

    1.这是Idea中的模块中的pom文件的配置,id要和settings.xml中server字段下的id的一致;

    2.两个url地址要指向私服中的url地址,不是公共仓库地址

9.发版

          <artifactId>base-commons</artifactId>  

       <groupId>com.husheng</groupId>  --idea默认没有,是需要手动指定 
         <version>1.0.2</version>     --idea默认没有,是需要手动指定 
      对于要发包的模块,idea中需要指定groupId,artifactId,以及版本   比如1.0.2 会发到发型版仓库中
      如果<version>1.0.2-SNAPSHOT</version> 就发到快照仓库中

    

    

    

10.引用

      <dependency>
              <groupId>com.husheng</groupId>
              <artifactId>base-commons</artifactId>
              <version>1.0.2</version>
        </dependency>

11.聚合工程中某个模块打包

  

   说明:

    1.项目中的依赖为  export-->common-->domain-->dao-->service-->fcade-->web  

    2.export为对外提供的接口,提供RPC调用,注意,删除<parent>标签,再进行发包

    

         

    注意:下图为common模块引用

     

 

   

之前查资料,有说pom.xml配置如下,则可以放弃某个模块打包,但是不清楚聚合咋处理......

     <properties>
            <maven.deploy.skip>true</maven.deploy.skip>
       </properties> 放弃某个模块打包 

猜你喜欢

转载自www.cnblogs.com/husheng1987hs/p/13173856.html