首先下载maven仓库软件
链接: 下载地址
下载完成后解压到某一个目录
然后进入目录 启动
然后进入本地地址http://localhost:8081/进入仓库
输入账号密码
初始密码在sonatype-work文件夹下面
进入后界面长这样
接下来就可以开始新建lib了,打开android studio 新建一个项目,新建一个lib
在gradle.properties里面配置相关信息
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Maven仓库的URL
MAVEN_REPO_RELEASE_URL=http://localhost:8081/repository/maven-releases/
# 对应maven的GroupId的值
GROUP=maven-releases
# 登录nexus ossde的用户名
NEXUS_USERNAME=admin
#登录nexus oss的密码
NEXUS_PASSWORD=admin
# groupid
GROUP_ID=cn.freebeat.lib
# type
TYPE=aar
# description
DESCRIPTION=this is a des
MAVEN_URL的地址取决于你想上传到哪个仓库,就点击copy按钮
就会出现这个仓库的地址
接下来
在lib的build下配置
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'maven'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
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
}
kotlinOptions {
jvmTarget = '1.8'
}
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: MAVEN_REPO_RELEASE_URL) {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
pom.project {
version '1.0.0'
artifactId 'testlib'
groupId GROUP_ID
packaging TYPE
description DESCRIPTION
}
}
}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
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'
}
同时在你需要引入lib的项目根build中导入仓库地址
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.0'
repositories {
google()
jcenter()
maven {
url MAVEN_REPO_RELEASE_URL
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url MAVEN_REPO_RELEASE_URL
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
接下来在你的lib build中点击uploadArchives
上传你的lib文件到仓库中
上传完成后,仓库会出现lib包
接下来就可以引用了
根据我的配置 我的地址如下
implementation 'cn.freebeat.lib:testlib:1.0.0'
完成
我的依赖中出现了测试的lib
nexus仓库部署到阿里云仓库流程也一致