`
iqeq00
  • 浏览: 62335 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Nexus 私服之三“Maven 与 Nexus 协同工作”

阅读更多

Nexus 私服之三“Maven 与 Nexus 协同工作”

 

1. Maven 从 Nexus 下载构件

 

a) 对当前 Maven 项目(项目 pom.xml

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus</name>
        <url>http://localhost:8888/nexus/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus</name>
        <url>http://localhost:8888/nexus/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

 

b) 对所有 Maven 项目(全局 settings.xml

<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus</name>
                <url>http://localhost:8888/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>Nexus</name>
                <url>http://localhost:8888/nexus/content/repositories/releases/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

 

    i.   activeProfile

         这个元素将 nexus 这个 profile 激活。

 

    ii.   缺点

         虽然所有 Maven 项目都是从 Nexus 下载构件,但是会发现 Maven 除了从Nexus 下载构件外,

         还会不时低访问中央仓库 central,我们希望的是所有Maven 下载请求都仅仅通过 Nexus,

         才能全面发挥私服的作用。

 

c) 配置镜像让 Maven 只使用私服

 

    可以创建一个匹配任何仓库的镜像,镜像的地址为私服,这样,

    Maven 对任何仓库的构件下载请求都会转到私服中。

<mirrors>
    <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://localhost:8888/nexus/content/groups/public/</url>
    </mirror>
</mirrors>

<profiles>
    <profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>http://central</url>
                <release>
                    <enabled>true</enabled>
                </release>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>central</id>
                <url>http://central</url>
                <release>
                    <enabled>true</enabled>
                </release>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>nexus</activeProfile>
</activeProfiles>

 

    i.   解释

         仓库及插件仓库配置,它们的 id 都为 central,相当于覆盖了超级 pom 中央仓库的配置,

         它们的 url 已经无关紧要了,因为所有请求都会通过镜像访问私服地址。

 

2. 部署构件至 Nexus

 

如果只为代理外部公共仓库,那么 Nexus 的代理仓库就已经能够完全满足需要了。

对于另一类 Nexus 仓库“宿主仓库”来说,它们的主要作用是存储组织内部的,或者一

些无法从公共仓库中获得的第三方构件,供大家使用。

 

a) Maven 部署构件至 nexus

 

    日常开发生成的快照版本构件可以直接部署到Nexus 中策略为 Snapshot 的宿主仓库中,

    项目正式发布版本构件应该部署到 Nexus 中策略为 Release 的宿主仓库中。

 

    i.   pom.xml 配置

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus Releases Repository</name>
        <url>http://localhost:8888/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus Snapshots Repository</name>
        <url>http://localhost:8888/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

 

    ii.  settings.xml 配置(用户名密码是你的登录名和密码

<servers>
    <server>
        <id>nexus-releases</id>
        <username>lichee</username>
        <password>lichee323</password>
    </server>
    <server>
        <id>nexus-snapshots</id>
        <username>lichee</username>
        <password>lichee323</password>
    </server>
</servers>

 

b) 手动部署第三方构件至 nexus

 

    Repositories  3rd party  Artifact Upload

 


 

    i.   GAV Definition

         如果构件是通过 Maven 构建的,那么可以在这个下拉列表中选择 From POM,

         否则就选 GAV Parameters(需要用户为该构件定义一个 Maven 坐标)。

 

    ii.   Select Artifact(s) to Upload

          此按钮从本机选择要上传的构件,然后单击 Add Artifact 按钮将其加入到上传列表中。

          Nexus 允许用户一次上传一个主构件和多个附属构件(即 Classifier)。最后,

          单击 Upload Artifact(s)按钮将构件上传到仓库中。

 

     (尽可能的把所有配置都给出来了,不过程序员就是懒,那来个更懒的办法,

         如有需要请下载附件settings.zip,修改里面用户名、密码、仓库地址,

         还有你的Nexus私服地址,替换掉你自己的settings.xml即可。)

 

  • 大小: 18.4 KB
3
2
分享到:
评论

相关推荐

    maven私服,nexus-3.23.0-03-unix.tar.gz

    ** Maven 私服与 Nexus** Maven 是一个广泛使用的项目管理和综合工具,它基于项目对象模型(Project Object Model,POM)的概念,帮助开发者管理构建过程、依赖关系以及项目的整个生命周期。在大型企业或开发团队中...

    tomcat, nexus,,maven

    标题中的“tomcat, nexus, maven”涉及的是Java Web...总结来说,Tomcat、Nexus和Maven是Java Web开发中不可或缺的工具,它们协同工作,简化了项目构建、依赖管理和应用部署的过程,提高了开发效率和项目的可维护性。

    nexus-2.11

    三、Nexus与Maven的协同工作 1. **代理远程仓库**:Nexus可以作为代理,缓存远程Maven中央仓库的依赖,减少网络延迟,提高构建效率。 2. **发布自定义构件**:当你的项目有自己的私有构件时,可以通过Nexus的...

    【nexus二进制库Jar包批量上传脚本工具】

    1. **Nexus配置**:你需要有一个运行的Nexus实例,并知道如何创建或选择合适的存储库(repository),比如Maven2或Generic类型的仓库。 2. **脚本参数**:脚本可能接受命令行参数,例如本地JAR文件路径、Nexus...

    maven聚合项目

    ** Maven聚合项目详解 ** Maven是一个强大的Java项目管理和构建工具,它通过提供标准化的构建过程,简化了项目的构建、依赖管理和部署。...通过这种方式,开发团队可以更有效地协同工作,保证项目的稳定性和一致性。

    jenkins+springboot+git自动化部署.docx

    【Jenkins+SpringBoot+Git自动化部署】 自动化部署是现代软件开发流程中的关键环节,它...在整个过程中,Jenkins作为核心工具,协调Maven和Git协同工作,Nexus则作为依赖管理和发布仓库,确保了组件的正确性和一致性。

Global site tag (gtag.js) - Google Analytics