当前位置: 移动技术网 > IT编程>开发语言>Java > android mac搭建Nexus3.+私有maven

android mac搭建Nexus3.+私有maven

2020年09月21日  | 移动技术网IT编程  | 我要评论
android 搭建Nexus3.+私有maven上次讲了搭建本地maven方法,这次说下Nexus3.+搭建方案(本地端口模拟远端)。安装篇

android 搭建Nexus3.+私有maven

上次讲了搭建本地maven方法,这次说下Nexus3.+搭建方案(本地端口模拟远端)。

安装篇

下载

https://www.sonatype.com/nexus/repository-oss/download

由于某种特殊原因,不能访问,这里我也只有mac的3.0版本提供下载:
链接:https://pan.baidu.com/s/1ny3zKC4TbJHjKabe33xEQQ 密码:dgvy

安装

mac上直接解压就行了。

启动

在控制台的该目录下输入以下命令:

/Users/apppp/Documents/nexus-mac/nexus-3.26.0-04-mac/nexus-3.26.0-04/bin/nexus start

启动nexus,然后在浏览器输入以下
或者*localhost:8081*可以进入nexus的操作界面了。
建议使用google浏览器打开,部分浏览器打不开

操作篇

进入页面会要求登录,需要账号和密码,nexus3.0 的 初始密码放在以下目录

/Users/apppp/Documents/nexus-mac/nexus-3.26.0-04-mac/sonatype-work/nexus3/admin.password

打开admin.password文件就可以查看初始账号和密码了。

初始密码登录后会要求修改账号和密码,安装提升流程走完就行了。最后到这个页面:
在这里插入图片描述

创建仓库

点到设置页面
在这里插入图片描述
在仓库选项下点击Create repository
在这里插入图片描述
选择Recipe为maven2(hosted),本地代理设置为hosted,如果与远端服务器链接需要选择proxy
在这里插入图片描述
选择后界面如下:
在这里插入图片描述
创建后:
在这里插入图片描述

创建后还是可以在设置页面点击修改的。

studio配置

原理跟本地maven配置大同小异。
在项目根目录创建upload-for-nexus.gradle,最好不同的仓库配置不同的gradle文件。

apply plugin: 'maven'

uploadArchives {
    repositories.mavenDeployer {
        repository(url:"http://127.0.0.1:8081/repository/news/") {
            authentication(userName:"admin", password:"admin123")
        }
        // 以com.android.support:appcompat-v7:25.1.0为对比
        pom.version="0.0.1" // 对应版本号 25.1.0
        pom.artifactId="news" // 对应 appcompat-v7 同时要跟仓库命名对应
        pom.groupId="com.hujin.wan.news" // com.android.support
    }
}

在news的module里面的build.gradle文件导入:

apply from: rootProject.file('upload-for-nexus.gradle')

在项目的根build.gradle文件下添加仓库的地址和密码:

apply from: "config.gradle"
buildscript {
    repositories {
        google()
        jcenter()
        maven {
            credentials {
                username = 'admin'
                password = 'admin123'
            }
            url "http://127.0.0.1:8081/repository/news/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath 'com.billy.android:cc-register:1.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
        //申明本地Macen仓库地址

        maven {
            url 'file:/Users/apppp/AndroidStudioProjects/wan/repository'
        }

        maven {
            credentials {
                username = 'admin'
                password = 'admin123'
            }
            url "http://127.0.0.1:8081/repository/news/"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

在右边侧边栏Gradle下:运行uploadArchives的task
在这里插入图片描述

出现如下就表示成功了:
在这里插入图片描述
再回到nexus上面的仓库里,就有我们上传的代码了:
在这里插入图片描述
本地就可以引用远程的包了:

    implementation 'com.hujin.wan.news:news:0.0.1'

注意点

  • 官网下载是需要梯子的
  • 仓库的命名要和studio里面的artifactId保持一致
  • 最好使用本地链接,而不是localhost

本文地址:https://blog.csdn.net/HUandroid/article/details/108594243

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网