nexus 搭建maven私服

 下载地址

    Download Nexus Repository OSS | Sonatype

下载好之后解压

在bin目录下shift+右键

点击在此处执行命令行

输入命令

在地址栏输入:http://localhost:8081

就看到下面的页面

点击箭头所指地方登陆:账号admin  密码admin123

点击箭头所指地方就出现方框中的类型

type表示仓库类型:

类型    用途
hosted    表示当前开发人员上传的,包括snapshots快照版本/releases稳定版本/3rd party第三方包三种仓库;表示当前开发人员上传的,包括snapshots快照版本/releases稳定版本/3rd party第三方包三种仓库;
proxy    表示中央服仓库,包括snapshots快照版本/releases稳定版本两种仓库;

maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar 
maven-releases:私库发行版jar 
maven-snapshots:私库快照(调试版本)jar 
maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。

以上配置完毕之后,添加一个链接到阿里云的库

    

然后出现如下界面 ,点击Create repository

点击maven2 (proxy)

       Name写成   aliyun-repository,这里建议用a开头(估计按字母排序将它排第一位),URL输入:http://maven.aliyun.com/nexus/content/groups/public/,其他默认值即可。

然后页面往下拉点击Create repository按钮保存后

点击Repositories然后点击maven-public仓库

将如下页面拉到最下面

选择刚刚新建的库(aliyun-repository)然后选择向右的箭头

然后点住拖到第一个

拖到第一个后保存即可

3.在maven的setting.xml的配置和项目中的运用!

  1. 对maven的配置文件setting的配置

一般会有一个公共仓库,和一个公司releases仓库,和一个快照仓库

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

  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/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>
    -->

    <pluginGroup>org.sonatype.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
     | 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>
    -->
    <!-- 配置权限,使用默认用户 -->
    <!--pom中id和这里的id相同-->

      <server>
        <id>nexus</id>
        <username>admin</username>
        <password>admin123</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 表示maven所有的请求都由nexus来处理-->
    <!-- <mirror>
           <id>ibiblio.org</id>
           <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
           <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
           <mirrorOf>central</mirrorOf>  -->
 <mirror>
   <id>nexus</id>
   <mirrorOf>central</mirrorOf>
   <name>my nexus</name>
   <!--这里写自己的私库的ip地址和端口号-->
    <url>http://192.168.5.127:8081/repository/maven-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>
  <id>nexus</id>
  <repositories>
    <repository>
      <id>central</id>
      <url>http://192.168.5.127:8081/repository/maven-releases/</url>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://192.168.5.127:8081/repository/maven-snapshots/</url>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases>
      <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
  </pluginRepositories>
</profile>

<!-- 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>
-->
</profiles>
        <!--激活私库信息的配置-->
<activeProfiles>

<activeProfile>Nexus</activeProfile>

</activeProfiles>
        <!-- activeProfiles
         | List of profiles that are active for all builds.
         |
        <activeProfiles>
          <activeProfile>alwaysActiveProfile</activeProfile>
          <activeProfile>anotherAlwaysActiveProfile</activeProfile>
        </activeProfiles>
        -->
  <localRepository>D:\Maven\m2\repository</localRepository></settings>

项目中pom.xml中配置 

  <!--maven 私库配置-->
 <distributionManagement>
    <repository>
      <id>nexus-releases</id>
      <name>Nexus Releases Repository</name>
      <url>http://192.168.5.127:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
      <id>nexus-snapshots</id>
      <name>Nexus Snapshots Repository</name>
      <url>http://192.168.5.127:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>

在工程中使用 clean install deploy -X 发布工程到快照版本

  • 24
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
搭建Maven私服可以使用Sonatype Nexus,它是一个功能强大的仓库管理器,可以帮助我们创建和管理Maven私服。下面是基于Nexus搭建Maven私服的详细步骤: 1. 准备环境:首先,确保你已经安装了Java环境,并且可以正常运行MavenNexus软件。 2. 下载和解压缩Nexus软件:从Sonatype官方网站下载最新版本的Nexus软件,并解压缩到合适的目录中。 3. 启动Nexus:使用命令行窗口进入Nexus软件的目录,然后执行 `./bin/nexus start` 命令来启动Nexus服务器。 4. 访问Nexus控制台:在浏览器中输入 `http://localhost:8081` 访问Nexus控制台,默认用户名密码都是 `admin`,登录成功后,可以看到Nexus的管理界面。 5. 创建Maven仓库:在Nexus控制台中,点击左侧菜单的 `Repositories`,然后点击 `Create repository` 来创建新的Maven仓库。根据需要选择 `Hosted repository` 或者 `Proxy repository`,然后填写相应的配置信息,如仓库名称、URL、布局等。 6. 配置Maven项目:在你的Maven项目的pom.xml文件中添加Nexus私服的配置信息,包括ID、URL等,用来指定将Maven构建输出部署到Nexus仓库中。 7. 部署和使用:使用 `mvn deploy` 命令将项目打包并部署到Nexus私服中,当其他开发人员或者CI/CD服务器需要下载依赖时,只需要修改项目的settings.xml文件,指定Nexus私服的URL和凭据即可。 8. 其他设置:你还可以在Nexus控制台里进行其他设置,比如用户管理、访问控制、仓库代理等。 总结一下,使用Nexus搭建Maven私服非常简单,只需要几个基本的步骤即可完成。通过搭建Maven私服,我们可以有效地管理和共享项目的依赖包,提升团队的开发效率和项目的可维护性。这对于生产环境中的项目非常重要。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半夜燃烧的香烟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值