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>

猜你喜欢

转载自blog.csdn.net/u014769528/article/details/83787870