Docker安装Nexus搭建Maven私服、部署引用jar包

docker run --restart="always" -d -p 8081:8081 --name nexus -v /opt/data/nexus-data:/nexus-data sonatype/nexus3 

注意点:若出现权限问题

chmod 777 nexus-data

内存占用情况:
image.png

1、欢迎页(默认账号:admin 默认密码:admin123)

image.png

2、仓库介绍

image.png

proxy:

是远程仓库的代理。比如说在nexus中配置了一个central repository的proxy,当用户向这个proxy请求一个artifact,这个proxy就会先在本地查找,如果找不到的话,就会从远程仓库下载,然后返回给用户,相当于起到一个中转的作用

Hosted:

是宿主仓库,用户可以把自己的一些构件,deploy到hosted中,也可以手工上传构件到hosted里。比如说oracle的驱动程序,ojdbc6.jar,在central repository是获取不到的,就需要手工上传到hosted里

Group:

是仓库组,在maven里没有这个概念,是nexus特有的。目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要在pom中配置多个地址。

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

3、部署jar包到私服

在setting.xml添加对应的用户名密码

 <servers>
    <server>
      <id>nexus-snapshots</id>    
      <username>username</username>
      <password>password</password>
    </server>
  </servers>

在pom文件中添加

    <distributionManagement>
        <snapshotRepository>
            <!--此名称要和settings.xml中设置的ID一致-->
            <id>nexus-snapshots</id>
            <name>nexus-snapshots-name</name>
            <url>http://ip:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

4、从私服中引用自己部署上传的jar包

在setting.xml文件中指定私服镜像

<mirrors>

     <mirror>
        <!--该镜像的唯一标识符。id用来区分不同的mirror元素。  -->
        <id>my-nexus</id>
        <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
        <mirrorOf>*</mirrorOf>
        <name>central repository</name>
        <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。  -->
        <url>http://ip:8081/repository/maven-public/</url>
    </mirror>
        <mirror>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
  </mirrors>

配置仓库

<profiles>
        <profile>
            <id>nexus</id>
            <!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。  -->
            <repositories>
                <!--发布版本仓库-->
                <repository>
                    <id>nexus</id>
                    <!--name随便-->
                    <name>Nexus Release Snapshot Repository</name>
                    <!--地址是nexus中repository(Releases/Snapshots)中对应的地址-->
                    <url>http://47.105.49.228:8081/repository/maven-releases/</url>
                    <!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <!--发现插件的远程仓库列表。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。-->
            <!--各节点的含义和repository是一样的-->
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <name>Nexus Release Snapshot Repository</name>
                    <url>http://47.105.49.228:8081/repository/maven-snapshots/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    <!--设置maven编译器级别-->
        <profile>
            <id>jdk18</id>
            <activation>
                <!--profile默认是否激活的标识 -->
                <activeByDefault>true</activeByDefault>
                <!--activation有一个内建的java版本检测,如果检测到jdk版本与期待的一样,profile被激活。 -->
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
  </profiles>

激活配置

 <!--激活配置-->
    <activeProfiles>
        <!--profile下的id-->
        <activeProfile>nexus</activeProfile>
    </activeProfiles>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 首先私服是一种衍生出来的特殊的Maven远程仓库,构建私服的好处请看3.5私服 可以帮助大家建立私服的仓库管理软件...
    zlcook阅读 13,640评论 0 32
  • 目前版本已经更新到了3.X下载地址:https://www.sonatype.com/download-oss-s...
    yunqing_71阅读 7,194评论 0 0
  • Maven 仓库 在 Maven 的术语中,仓库是一个位置(place)。Maven 仓库是项目中依赖的第三方库,...
    acc8226阅读 7,372评论 0 1
  • Nexus是Maven仓库管理器,管理开发所需要的构件。如果你每次都是从Apache提供的Maven中央仓库去下载...
    点融黑帮阅读 9,255评论 0 6
  • 介绍 私服的优点:解决中央仓库网络、重复下载、本公司非公开组件多项目依赖等问题。 在团队协作开发中,为了提高开发效...
    madfrog_hc阅读 12,853评论 0 7

友情链接更多精彩内容