目录

Nexus简介

一、安装nexus

1. 方式一: 使用压缩包安装nexus

1) 下载安装包

2) 修改配置 

3) 启动nexus

4) 修改密码

4) 将nexus添加为service

2. 方式二: 使用Kubernetes 部署nexus

二、使用Nexus创建仓库

1、创建一个代理仓库

2、查看私服连接

3、配置pom.xml

4、配置maven的settings.xml 

5、将本地项目发布到私服。


Nexus简介

        Nexus是一款开源的仓库管理软件,我们可以借助nexus搭建一个私有的依赖(jar)仓库, 并且我们可以手动将jar 传到nexus上, 由nexus帮你生成maven坐标,管理方便。

一、安装nexus

        本文介绍2种方式安装nexus, 一种采用压缩包的方式直接执行.sh文件启动, 另一种方式采用kubernets部署nexus。

1. 方式一: 使用压缩包安装nexus

1) 下载安装包

下载 nexus安装包, 我用的是3.19.1版本:

nexus 上传releases nexus部署_nexus 上传releases

 丢到centos服务器里后,使用命令解压

tar -zxvf nexus-3.19.1-01-unix.tar.gz

另贴上我的网盘连接,需要自取。

链接:https://pan.baidu.com/s/1bQO6dPn3LYPHO2xzY7XbOQ  提取码:dc85 

解压到 /usr/local路径下:

nexus 上传releases nexus部署_nexus_02

2) 修改配置 

进入到nexs-3.19.1-01目录,修改~/etc/nexus-default.properties, 可指定启动的端口:

nexus 上传releases nexus部署_nexus_03

nexus 上传releases nexus部署_运维_04

 配置好后,进入到bin目录下启动nexus

cd /usr/local/nexus-3.19.1-01/bin/

nexus 上传releases nexus部署_nexus_05

3) 启动nexus

执行命令

./nexus start

访问: 192.168.232.129:8081, 出现如下画面说明安装成功:  

nexus 上传releases nexus部署_linux_06

nexus 上传releases nexus部署_centos_07

4) 修改密码

登录用户: admin,  登录默认密码存放在/usr/local/sonatype-work/nexus3/admin.password 路径,登录成功后,需要提醒你修改密码:

nexus 上传releases nexus部署_运维_08

 修改成功后,会进入到首页:

nexus 上传releases nexus部署_nexus_09

同样也可以执行 ./nexus stop 命令停止 nexus server。 

4) 将nexus添加为service

安装成功后,接着可以设置开机自启 nexus, 在路径/etc/rc.d/init.d添加文件nexusd, 直接使用如下命令:

vim /etc/rc.d/init.d/nexusd

编写shell脚本配置如下,

注: 开头的chkconfig, description都要有,要不然会出现不支持chk的报错!

#!/bin/bash
#chkconfig:345 61 61
#description:nexus
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0
nexus=/usr/local/nexus-3.19.1-01
startup=/usr/local/nexus-3.19.1-01/bin/nexus
shutdown=/usr/local/nexus-3.19.1-01/bin/nexus
start(){
echo -n $"Starting nexus service:"
sh $startup start
echo $?
}
stop(){
echo -n $"Stoping nexus service:"
sh $shutdown stop
echo $?
}
restart(){
stop
start
}
status(){
ps -ef|grep nexus
}
if "$1" in
(start|stop|restart|status)
then 
 echo $1
else
 echo "not support  operation!"
fi

保存退出后,加载并启用nexusd, 由chkconfig去加载

chkconfig -add nexusd
chkconfig nexusd on

如果修改nexusd文件,需要重新刷新配置,执行如下命令即可:

systemctl daemon-reload

启动nexus:

systemctl start nexusd

 

nexus 上传releases nexus部署_linux_10

停止nexus:

systemctl stop nexusd

还可以重启:

systemctl restart nexusd

nexus 上传releases nexus部署_linux_11

 查看nexus的服务状态:

nexus 上传releases nexus部署_linux_12

 启动成功! 访问 http://192.168.232.129:8081 ,如果能出现nexus首页,表明nexus启动成功!

nexus 上传releases nexus部署_centos_13

        这样配置完后,重新启动机器,nexus仓库可以自启。 

2. 方式二: 使用Kubernetes 部署nexus

        编写nexus-persisit.yaml文件放在centos 系统指定路径: /root/kubernetes/config/nexus下

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nexus-data
spec:
  capacity:
    storage: 3Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nexus-nfs
  cinder:
    volumeID: a198bce4-ba0f-7e13-8f0c-55e3126-nexus # 改路径为映射到本机的  /var/lib/kubelet/plugins/kubernetes.io/cinder/mounts
    fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexus-data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 3Gi
  storageClassName: nexus-nfs
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nexus-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus
  template:
    metadata:
      labels:
        app: nexus
    spec:
      containers:
        - name: nexus
          image: sonatype/nexus3
          imagePullPolicy: IfNotPresent
          ports:
            -  containerPort: 8081
            -  containerPort: 8082
            -  containerPort: 8083
          volumeMounts:
            - mountPath: /nexus-data
              name: nexus-data
      volumes:
        - name: nexus-data
          persistentVolumeClaim:
            claimName: nexus-data-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: nexus-svc
spec:
  selector:
    app: nexus
  type: NodePort
  ports:
    - name: web
      protocol: TCP
      port: 8081
      targetPort: 8081
      nodePort: 30081
    - name: docker
      protocol: TCP
      port: 8082
      targetPort: 8082
      nodePort: 30082
    - name: maven
      protocol: TCP
      port: 8083
      targetPort: 8083
      nodePort: 30083

kubectl apply  -f  nexus-persist.yaml, 执行成功后,查看pod。

nexus 上传releases nexus部署_nexus 上传releases_14

        查看service:  

nexus 上传releases nexus部署_centos_15

         访问: http://192.168.31.129:30081/, 能进入首页表示搭建成功。

        注意: 挂载数据时,kubernetes为会pv提供一个存储路径volumeID, 然后会在

 /var/lib/kubelet/plugins/kubernetes.io/cinder/mounts 路径下去寻找该volumeID, 如果不存在那么需要手动创建并授权给目录读写权限。

nexus 上传releases nexus部署_nexus 上传releases_16

        如果没有cinder指定的目录,那么会出现mount failed的报错问题。

二、使用Nexus创建仓库

         进入到首页后,我们可以在Repositories下看到4个主要的默认仓库:  maven-central、maven-public、maven-releases、maven-snapshots。 

nexus 上传releases nexus部署_linux_17

  • maven-central:核心中央仓库,是nexus的最重要的仓库。
  • maven-public:公共仓库,所有仓库。
  • maven-releases:存放jar的release仓库。
  • maven-snapshots:保存快照的仓库。

        平时我们用的比较多阿里云镜像,如果我们本地没有一些jar, 也不想手动一个一个的把镜像上传到nexus仓库,那我们可以先把阿里云仓库作为一个代理仓库,就是说先从阿里云的仓库中将需要的镜像pull 到nexus上,然后本地仓库根据需要再向nexus拉取。

1、创建一个代理仓库

        点击create repositories---> maven2(proxy)

nexus 上传releases nexus部署_linux_18

         阿里云仓库地址:  https://maven.aliyun.com/repository/public

nexus 上传releases nexus部署_centos_19

         可以添加用户名和密码进行认证,根据需要设置: 

nexus 上传releases nexus部署_nexus_20

         最关键的一步: 将刚创建的 proxy仓库加入到 maven-public仓库中:

nexus 上传releases nexus部署_运维_21

2、查看私服连接

        上面的操作是为了后面的使用做准备,我们可以将私服的地址配置到自己的project里了, 下面是我们的仓库的镜像地址:

http://192.168.232.129:8081/repository/maven-public/

nexus 上传releases nexus部署_运维_22

        接着我们只需要将该地址配置到maven里就可以访问了。

3、配置pom.xml

        将url配置到pom里,父标签为Project标签

<distributionManagement>
        <repository>
            <id>nexus</id>
            <url>http://192.168.232.129:8081/repository/maven-public/</url>
        </repository>

    </distributionManagement>

        插件仓库的配置可暂时使用阿里云:

<pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://maven.aliyun.com/repository/public</url>
        </pluginRepository>
    </pluginRepositories>

4、配置maven的settings.xml 

        在settings.xml添加mirror:

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

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.home}/conf/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <localRepository>F:/local-repo</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>

<server>  
    <id>nexus</id>  
    <username>admin</username>  
    <password>nexus847652.</password>  
</server>

<server>  
    <id>Snapshots</id>  
    <username>admin</username>  
    <password>nexus847652.</password>  
</server>
<server>   
	<id>Releases</id>   
	<username>admin</username>   
	<password>nexus847652.</password>   
</server> 

    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->

<!--
<mirror>  
      <id>aliyun</id>  
      <name>aliyun Maven</name>  
      <mirrorOf>*</mirrorOf>  
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>  
 </mirror>-->



  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->

<profile>  
       <id>dev</id>  
       <repositories>  
          <repository> 
          <id>nexus</id>  
          <url>http://192.168.31.129:30081/repository/maven-public/</url>  

          <!--是否下载releases构件-->

          <releases>  
              <enabled>true</enabled>  
          </releases>  


          <snapshots>  
              <enabled>true</enabled>  
          </snapshots>  

        </repository>  

       </repositories> 

        <pluginRepositories> 

          <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件,暂时配置阿里云插件-->
          <pluginRepository>
             <id>central</id>

                <name>public plugin</name>

                <url>https://maven.aliyun.com/nexus/content/groups/public/</url>

                <layout>default</layout>

                <releases>

                    <enabled>true</enabled>

                </releases>

                <snapshots>

                    <enabled>false</enabled>

                </snapshots>
           </pluginRepository>
       </pluginRepositories> 
</profile>

  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->




  <activeProfiles>
      <activeProfile>dev</activeProfile>
  </activeProfiles>


</settings>

        1. 如果在idea里的终端里执行的mvn命令,那么idea会默认读取到用户文件夹里.m2/里面的settings.xml。

nexus 上传releases nexus部署_运维_23

        2. 如果在coonfigurations里面配置的mvn命令,那么会适应自己maven工具所在的config目录里的settings.xml。

nexus 上传releases nexus部署_nexus 上传releases_24

nexus 上传releases nexus部署_运维_25

        进入项目,刷新maven依赖,刷新页面,在终端执行mvn clean isntall 会发现已经开始下载依赖了:

nexus 上传releases nexus部署_运维_26

下载完成后,项目中会出现jar, 如上图,我们也可以从nexus里的Browse面板里查看依赖占内存,jar的路径等。

nexus 上传releases nexus部署_nexus 上传releases_27

 另外在更新maven依赖的时候可以到nexus仓库中看到已经缓存到里面的jar包:

nexus 上传releases nexus部署_运维_28

至此nexus 私服搭建流程结束。 

5、将本地项目发布到私服。

mvn clean package deploy命令。

        pom.xml 文件如下,需要添加maven-deploy-plugin和maven-release-plugin两个插件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.bingbing.sh</groupId>
    <artifactId>hire-management-user-service</artifactId>
    <version>0.0.1-RELEASE</version>
    <name>hire-management-user-service</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
        <spring.cloud.alibaba.version>2.2.1.RELEASE</spring.cloud.alibaba.version>

    </properties>


    <packaging>pom</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>


    <modules>
        <module>user-service</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring.cloud.alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>

                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.2</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.4.1</version>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.7</version>
                </plugin>
            </plugins>


        </pluginManagement>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://maven.aliyun.com/repository/public</url>
        </pluginRepository>
    </pluginRepositories>


    <!--将本地jar发布到私服-->
    <distributionManagement>
        <repository>
            <id>maven-releases</id>
            <url>http://192.168.31.129:30081/repository/maven-releases/</url>
        </repository>

        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://192.168.31.129:30081/repository/snapshots/</url>
        </snapshotRepository>

    </distributionManagement>

</project>

        这样配置完后,需要在maven的settings.xml里加一个server配置, 其中id对应pom.xml文件里的id, pom.xml文件里的repository的id与nexus私服仓库里的id保持一致,比如我的nexus的release仓库叫maven-releases,那么id 都要用maven-releases。

<server>  
    <id>maven-snapshots</id>  
    <username>admin</username>  
    <password>nexus847652.</password>  
</server>
<server>   
	<id>maven-releases</id>   
	<username>admin</username>   
	<password>nexus847652.</password>   
</server>

nexus 上传releases nexus部署_linux_29

 发布成功后,进入到release仓库和public仓库都可以看到刚发布的服务:

nexus 上传releases nexus部署_nexus 上传releases_30

        再次执行同样的命令,idea报错:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project user-service: Failed to deploy artifacts: Could not transfer artifact com.bingbing.sh:user-service:jar:0.0.1-RELEASE from/to maven-releases (http://192.168.31.129:30081/repository/maven-releases/): Failed to transfer file: http://192.168.31.129:30081/repository/maven-releases/com/bingbing/sh/user-service/0.0.1-RELEASE/user-service-0.0.1-RELEASE.jar. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases.

        我们只需要进入nexus,重新设置repositry的deployment policy 为allow redeploy即可:

nexus 上传releases nexus部署_nexus_31