搭建nexus maven仓库并利用Android studio上传库

433 阅读2分钟

搭建nexus maven

下载nexus maven

进入官方网站下载 页面如下:

}8[KXDU_YKK55_WQTE8{X.png

在红红框内输入信息后下载,可以随便填不会验证,注意邮箱不支持谷歌QQ等邮箱,需要公司邮箱后缀。

搭建nexus

下载后获取大压缩文件,解压到任一文件夹下得到如下文件:

1{B5PFK5F8V(3Q7H{95B@Y.png

以我的版本为例打开nexus-3.37.3-02文件夹下的bin文件,在此处打开shell命令行输入命令

.\nexus.exe /run

等待运行成功之后打开浏览器输入http://localhost:8081 如果打开了如下页面

3XWZ9UF55I}O%A~CRD1N7A.png

即代表运行成功,登录时的管理员默认密码在一个叫admin.password的文件夹下,用户名就是admin 密码在文件里 登录之后就可以自己新建仓库了

@%SPU2ZO3QXKGYFOCM54.png

根据需要新建仓库类型

IO`IZJS_{(5AW@UZH7~B.png

Androidsudio上传仓库

上传时我这边遇到问题 由于是新版所以创建的时默认用的gradle7的版本,但是上传时一直i提示jdk不匹配所以我就降级了

在library的gradle配置如下:

plugins {
    id 'com.android.library'
    id 'maven-publish'
}

android {
    compileSdk 31

    defaultConfig {
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = '前缀 例如:com.test.library'
                artifactId = '标识,例如:zpp'
                version = '版本号 例如:1.0.7'
            }
        }

        repositories {
            maven {
                allowInsecureProtocol true
                name = "nexus" //可选
                url = '你的仓库地址/'
                credentials {
                    username = '你的用户名'
                    password = '你的密码'
                }
            }
        }
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

最后在终端离输入

gradlew publish

等待成功提示即可,失败了看日志解决

成功之后即可在库里看到我们刚才上传的依赖

%3N{@YV5RL1}D(HYRPD98EM.png