nexus

1、到官网下载nexus包nexus-2.13.0-01-bundle.zip

2、下载下来后解压

3、配置环境变量

即解压后的bin目录

4、使用cmd输入nexus install安装

5、安装完成后输入nexus start启动服务

6、打开浏览器localhost:8081/nexus可以看到一个页面

7、(1)建立maven工程配置pom.xml方式来指定jar的下载仓库

<repositories>
        <repository>
            <id>nexus</id>
            <name>nexus repository</name>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://localhost:8081/nexus/content/repositories/central/</url>
        </repository>
    </repositories>
<pluginRepositories>
        <pluginRepository>
            <id>nexus-plugin</id>
            <name>nexus plugin</name>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://localhost:8081/nexus/content/repositories/central/</url>
        </pluginRepository>
    </pluginRepositories>

(2)通过maven的setting.xml的方式来配置,放在settings标签内

<profile>
      <id>myPlugin</id>
      <pluginRepositories>
        <pluginRepository>
            <id>nexus-plugin</id>
            <name>nexus plugin</name>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://localhost:8081/nexus/content/repositories/central/</url>
        </pluginRepository>
    </pluginRepositories>

    </profile>
    
    <profile>   
      <id>myJar</id>   
      <!--  在这里加入<repositories>及<pluginRepositories>  --> 
      <repositories>
        <repository>
            <id>nexus</id>
            <name>nexus repository</name>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <url>http://localhost:8081/nexus/content/repositories/central/</url>
        </repository>
    </repositories>
    </profile>   
  
   
  <!-- 声明哪些profile被激活,或根据某些条件激活 --> 
  <activeProfiles>   
    <activeProfile>myJar</activeProfile> 
    <activeProfile>myPlugin</activeProfile>    
  </activeProfiles>  

(3)使用mirror的方式,推荐大家使用

http://maven.aliyun.com/nexus/content/groups/public这个阿里巴巴的maven仓库,速度很快
<mirror>
      <id>mirrorId</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <!-- <url>http://my.repository.com/repo/path</url> 
      http://uk.maven.org/maven2/
      -->
     <!-- <url>http://maven.aliyun.com/nexus/content/groups/public</url>-->
      
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </mirror>

8、向nexus发布工程使用命令clean deploy -Dmaven.test.skip=true

(1)创建两个仓库

 

只对红框部分修改,其他的不变

继续添加snapshot仓库

9、添加权限,当你创建了自己的仓库的时候,默认只有查看的权限,所以需要添加其他的crud的权限

添加demo release权限,这里的demo release是为了与已经存在demo release-(view)权限名一致,不仅仅只是仓库名。

添加demo snapshot权限

 添加角色

添加demo角色,这个名字ID可以随你随便取,然后点击add

添加这个角色可以使用的权限

全勾上,保存即可

有了角色,总得有人充当这个角色吧!现在来创建一个用户

添加的任务完成

10、发布的实现

在pom.xml中添加

<distributionManagement>
        <repository>
            <id>nexusRelease</id>
            <name>nexus release</name>
            <url>http://localhost:8081/nexus/content/repositories/demo-release/</url>
        </repository>
        <!-- 允许snapshot版本的发布 -->
        <snapshotRepository>
            <id>nexusSnapshot</id>
            <name>nexus snapshot</name>
            <url>http://localhost:8081/nexus/content/repositories/demo-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>

这样还没完,还需要在maven的setting.xml中的servers标签内添加server,否则报错

<server>
      <id>nexusRelease</id>
      <username>demo</username>
      <password>demo</password>
    </server>
    
    <server>
      <id>nexusSnapshot</id>
      <username>demo</username>
      <password>demo</password>
    </server>

OK!可与发布了。

原文地址:https://www.cnblogs.com/honger/p/5874122.html