Maven私服搭建(Nexus Repository Manager 3)

下载和安装

下载地址:https://help.sonatype.com/repomanager3/download

注意:Nexus Repository Manager 3是一个Java服务器应用程序,安装需要 jdk1.8以上的版本。

下载解压后,用命令行到解压目录的bin目录下运行 nexus.exe /run(Linux运行./nexus run),启动完成后会显示“Started Sonatype Nexus”:

-------------------------------------------------

Started Sonatype Nexus OSS 3.16.2-01

-------------------------------------------------

访问Nexus管理后台

Nexus管理后台地址:http://localhost:8081/
点击右上角Sign in登录,默认账号和密码为:admin/admin123

在Repositories 仓库管理界面中有多种默认的仓库,也可以添加新的仓库,本实例直接使用默认的仓库:
maven-central,Type为proxy,表示代理仓库。代理仓库用来代理远程仓库(maven-central代理的是超级POM中配置的Maven中央仓库),当在下载组件时,如果代理仓库搜索不到,则会把请求转发到远程仓库从远程仓库下载。从远程仓库下载后会缓存到代理仓库,下次还有该组件的请求则会直接到代理仓库下载,不会再次请求远程仓库。

maven-releases/maven-snapshots,Type为hosted,表示为宿主仓库。宿主仓库主要用来部署团队内部使用的内部组件,默认的maven-releases和maven-snapshots分别用来部署团队内部的发布版本组件和快照版本组件。

配置代理仓库

配置settings.xml:

<settings>
   <!-- 配置镜像,此处拦截所有远程仓库的请求到代理仓库-->
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-central/</url>
    </mirror>
  </mirrors>
  <!-- 配置远程库和远程插件库-->
  <profiles>
    <profile>
      <id>nexus</id>
      <!-- Maven用于填充构建系统本地存储库的远程仓库集合-->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <!-- 类似于repositories元素,指定Maven可以在哪里找到Maven插件的远程仓库位置-->
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <!-- 激活profiles配置 -->
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

创建Maven项目,pom.xml如下:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.nocoffee</groupId>
  <artifactId>coffee-api</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>coffee-api</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

执行mvn clean,执行mvn clean需要下载maven-clean-plugin插件,通过Browse界面可以看到因为执行mvn clean而下载的maven-clean-plugin.jar:

注意:如果界面为空,表示没有下载,原因是之前下载过该插件到本地仓库,需要把本地仓库的maven-clean-plugin插件删除,我的本地仓库路径为D:\Reporsitory,所以需要删掉文件夹:D:\Reporsitory\org\apache\maven\plugins\maven-clean-plugin,然后重新构建即可。

配置宿主仓库

settings.xml增加如下配置:

<servers>
     <server>
        <id>nexus</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
</servers>

配置pom.xml:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.nocoffee</groupId>
  <artifactId>coffee-api</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>coffee-api</name>
  <url>http://maven.apache.org</url>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <distributionManagement>
        <repository>
        <id>nexus</id>
        <name>maven-releases</name>
        <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
        <id>nexus</id>
        <name>maven-snapshots</name>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
   </distributionManagement>
</project>

执行mvn clean deploy将项目打包并发布到宿主仓库,构建成功后到Browse中maven-snapshots库查看(因为项目版本为0.0.1-SNAPSHOT,是带SNAPSHOT的快照版本):

maven-releases库

需要将项目版本改成发布版本,在pom.xml中0.0.1-SNAPSHOT去掉-SNAPSHOT,改为0.0.1。重新执行mvn clean deploy:

注意:maven-releases库默认不能重新发布,需要可重新发布则需要修改该仓库配置。
测试重新发布到maven-releases库,执行mvn clean deploy将会构建失败:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.112 s
[INFO] Finished at: 2019-06-10T16:34:29+08:00
[INFO] Final Memory: 18M/164M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project coffee-api: Failed to deploy artifacts: Could not transfer artifact com.nocoffee:coffee-api:jar:0.0.1 from/to nexus (http://localhost:8081/repository/maven-releases/): Failed to transfer file: http://localhost:8081/repository/maven-releases/com/nocoffee/coffee-api/0.0.1/coffee-api-0.0.1.jar. Return code is: 400, ReasonPhrase: Repository does not allow updating assets: maven-releases. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

将maven-releases库中Deployment pollcy改为Allow redeploy既可:

原文地址:https://www.cnblogs.com/seve/p/10982603.html

时间: 2024-07-30 19:29:23

Maven私服搭建(Nexus Repository Manager 3)的相关文章

maven私服搭建nexus介绍(二)

1.各个仓库介绍 Hosted:宿主仓库 主要放本公司开发的SNAPSHOTS测试版本,RELEASES正式发行版.合作公司第三方的jar包. Proxy:代理仓库 代理中央仓库:代理Apache下测试版本jar包 Group:组仓库 存放各种仓库(宿主仓库,代理仓库) Virtual:虚拟仓库(废弃) 代理maven1版本的jar包 2.组仓库可进行配置,存放那个仓库(配置后 通过组仓库即可访问配置过的仓库) 3.maven中私服的配置 jar包上传配置 setting.xml中的配置 <se

Maven私服搭建 Nexus

官网: http://books.sonatype.com/nexus-book/reference3/ 参考: http://www.cnblogs.com/kevingrace/p/6201984.html http://blog.csdn.net/xyzjl/article/details/53148398 http://blog.csdn.net/smartbetter/article/details/55116889

Nexus Repository Manager的应用

安装和运行Nexus Repository Manager很简单.您可以将存档文件解压缩到您有完全访问权限的目录中,也可以使用Docker映像安装它. 安装包下载:https://help.sonatype.com/repomanager3/download安装参考文档:https://help.sonatype.com/repomanager3 1, 下载安装包https://help.sonatype.com/repomanager3/download/download-archives--

Nexus Repository Manager 3 RCE CVE-2019-7238

Nexus Repository Manager 3 RCE CVE-2019-7238 0x00 参考链接 https://support.sonatype.com/hc/en-us/articles/360017310793-CVE-2019-7238-Nexus-Repository-Manager-3-Missing-Access-Controls-and-Remote-Code-Execution-February-5th-2019 0x01 影响版本 Nexus Repository

Linux安装配置maven以及搭建nexus私服

http://nlslzf.iteye.com/blog/812995 一.软件准备 1.apache-maven-3.0-bin.tar.gz 下载地址:http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0-bin.tar.gz 2.nexus-oss-webapp-1.8.0-bundle.tar.gz 下载地址:http://nexus.sonatype.org/downloads/ 二.maven安装配置

Nexus Maven 私服搭建

1.下载Nexus安装文件:http://www.sonatype.org/nexus/go ,目前是nexus-2.13.0-01-bundle.tar.zip这个最新版本: 2.解压到任意目录,我这里解压到E盘,进入F:\nexus-2.13.0-01\bin\jsw\windows-x86-64,点击install-nexus.bat安装成为windows服务,这里选择自己计算机对应的文件: 3.访问http://localhost:8081/nexus/,这就是私服:默认用户名admin

centos7 nexus maven私服搭建

[[email protected] vhost]# uname -r3.10.0-229.4.2.el7.x86_64 1 安装maven# yum install maven2 下载nexusNexus下载地址:http://www.sonatype.org/nexus/archived/#step2top # wget http://download.sonatype.com/nexus/oss/nexus-2.11.3-01-bundle.tar.gz# tar -zxvf nexus-

Maven私服搭建

1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载和浪费了外网带宽,如果网速慢的话,还会影响项目的进程.很多情况下项目的开发都是在内网进行的,连接不到maven仓库怎么办呢?开发的公共构件怎么让其它项目使用?这个时候我们不得不为自己的团队搭建属于自己的maven私服,这样既节省了网络带宽也会加速项目搭建的进程,当然前提条件就是你的私服中拥有项目所需的

Maven 私服搭建

为什么搭建Maven  私服 因为在 java开发中,经常用到第三方的 jar 包依赖,而这些依赖很乱,很杂,构建过程中经常产生意想不到的冲突,比如  jar 包冲突,版本不对等.如果能够用软件的方式,一条命令,快速的搭建 ssh(struct,spring,hibernate),ssi(struct, spring, ibatis) 开发环境,那会节省我们很多的时间去专注研发上 . 私服其实就是一种maven服务器,仅仅服务于某个公司,政府.把它架设在局域网的内部有很多好处,下载依赖变得快了,