maven 私服 nexus 使用

全局使用私服下载jar包express

1.修改maven全局配置文件 setting.xmlapache

<?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.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">
    <pluginGroups>
        <pluginGroup>org.apache.maven.plugins</pluginGroup>
    </pluginGroups>

<!--连接仓库时用到的用户名 密码  经过id对应-->
    <servers>
        <server>
            <id>nexus-release</id>
            <username>admin</username>
            <password>1q</password>
        </server>
        <server>
            <id>nexus-snapshot</id>
            <username>admin</username>
            <password>1qa</password>
        </server>
    </servers>


    <profiles>

        <profile>
            <!--            对应profile activeProfile字段-->
            <id>nexus</id>
            <!--依赖仓库-->
            <repositories>
                <repository>
                    <id>nexus</id>
                    <url>http://192.168.1.7:8081/repository/maven-public/</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </releases>
                    <snapshots>
                        <updatePolicy>always</updatePolicy>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <!--插件仓库-->
            <pluginRepositories>
                <pluginRepository>
                    <id>Aliyun</id>
                    <name>Maven Aliyun Mirror</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>


        </profile>

    </profiles>

    <!--    激活profiles才能生效-->
    <activeProfiles>
        <!--        对应profile中id字段-->
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

    <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>


    <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>aliyun</id>-->
        <!--            <name>aliyun maven</name>-->
        <!--            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>-->
        <!--            <mirrorOf>*</mirrorOf>-->
        <!--        </mirror>-->

        <!--        <mirror>-->
        <!--            <id>nexus</id>-->
        <!--            <url>http://192.168.1.7:8081/repository/maven-public/</url>-->
        <!--            <mirrorOf>*</mirrorOf>-->
        <!--        </mirror>-->
    </mirrors>
</settings>

2.在项目中引用私服app

<dependency>
  <groupId>com.iskytrip</groupId>
  <artifactId>iskytrip-framework-util</artifactId>
  <version>1.3</version>
</dependency>

3.编译发布jar包less

    1).在项目pom.xml中配置私服地址maven

<distributionManagement>
    <repository>
        <id>nexus-release</id>
        <name>release</name>
        <url>http://192.168.1.7:8081/repository/maven-releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshot</id>
        <name>snapshot</name>
        <url>http://192.168.1.17:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
</distributionManagement>

    2).在setting.xml中配置私服上传用户名和密码ide

<!--连接仓库时用到的用户名 密码  经过id对应-->
    <servers>
        <server>
            <id>nexus-release</id>
            <username>admin</username>
            <password>1qa</password>
        </server>
        <server>
            <id>nexus-snapshot</id>
            <username>admin</username>
            <password>1ol.</password>
        </server>
    </servers>

使用 mvn clean deploy 命令发布测试

说明:ui

release版本和snapshot版本区别this

在pom.xml中配置<version>1.0-snapshot</version>即上传到snapshot库, 如配置<version>1.0</version>即上传release库url

snapshot库中会根据时间自动生成版本后缀, 如: 1.0-20190826.073546-1 ,引用时也只须要<version>1.0-snapshot</version>便可引用最新snapshot库

 

不一样maven库区别

maven-central  -> maven中央公共库

maven-public   -> 仓库组 可添加多个仓库, 项目只需引用组便可引用多个仓库

maven-release -> 发布库

maven-snapshot -> 测试库  

相关文章
相关标签/搜索