Docker 相关应用(14)-Docker 上安装Nexus(maven私服)

安装

$ docker images
$ docker docker pull sonatype/nexus3

docker-compose.yml

version: '3.1'
services:
  nexus:
    restart: always
    image: shifudao/nexus3
    container_name: nexus
    ports:
      - 8081:8081
    volumes:
      - /usr/local/docker/nexus/data:/nexus-data
$ cd /usr/local/
$ mkdir docker
$ cd docker
$ mkdir nexus
$ vi docker-compose.yml
$ docker-compose up -d  #守护态运行
#报错:文件夹没权限
$ docker-compose down 
$ chmod 777 data/
$ docker-compose up
$ docker ps -a

在项目中使用

配置认证信息

在Maven settings.xml中添加Nexus认证信息(servers节点下)

<server>
    <id>nexus-releases</id>
    <username>admin</username>
    <password>15955655592</password>
</server>

<server>
    <id>nexus-snapshots</id>
    <username>admin</username>
    <password>15955655592</password>
</server>

pom.xml中添加

<distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.197.138:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshots Repository</name>
            <url>http://192.168.197.138:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
  • 注意:ID名称必须要与settings.xml中servers配置的ID名称保持一致
  • 项目版本号中有SNAPSHOT表示的,会发布到Nexus Snapshots Repository,否则发布到Nexus Releases Repository,并根据ID去匹配授权账号

IDEA中运行maven指令

$ mvn deploy
![nexus拉取最新快照版理解.png](https://upload-images.jianshu.io/upload_images/17985621-e7ffb469fbdc20fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

上传第三方 JAR 包

# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar
mvn deploy:deploy-file 
  -DgroupId=com.aliyun.oss 
  -DartifactId=aliyun-sdk-oss 
  -Dversion=2.2.3 
  -Dpackaging=jar 
  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/maven-3rd/ 
  -DrepositoryId=nexus-releases

注意事项:

  • 建议在上传第三方 JAR 包时,创建单独的第三方 JAR 包管理仓库,便于管理有维护。(maven-3rd)
  • -DrepositoryId=nexus-releases 对应的是 settings.xml 中 Servers 配置的 ID 名称。(授权)
私服好处.png

配置代理仓库

pom.xml

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://127.0.0.1:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。