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 -> 測試庫  

相關文章
相關標籤/搜索