您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關maven私服nexus怎么用的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
1.修改maven全局配置文件 setting.xml
<?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.在項目中引用私服
<dependency> <groupId>com.iskytrip</groupId> <artifactId>iskytrip-framework-util</artifactId> <version>1.3</version> </dependency>
3.編譯發布jar包
1).在項目pom.xml中配置私服地址
<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中配置私服上傳用戶名和密碼
<!--鏈接倉庫時用到的用戶名 密碼 通過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 命令發布
說明:
release版本和snapshot版本區別
在pom.xml中配置<version>1.0-snapshot</version>即上傳到snapshot庫, 如配置<version>1.0</version>即上傳release庫
snapshot庫中會根據時間自動生成版本后綴, 如: 1.0-20190826.073546-1 ,引用時也只需要<version>1.0-snapshot</version>即可引用最新snapshot庫
不同maven庫區別
maven-central -> maven中央公共庫
maven-public -> 倉庫組 可添加多個倉庫, 項目只需引用組即可引用多個倉庫
maven-release -> 發布庫
maven-snapshot -> 測試庫
感謝各位的閱讀!關于“maven私服nexus怎么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。