之前下载的安装包,现在直接拿来用.
下载地址:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.18.1-01-win64.zip
1.安装Nexus并创建仓库
1.解压即完成安装, 我安装到了本地D:\soft\nexus-3.18.1-01-win64目录中.
2.打开D:\soft\nexus-3.18.1-01-win64\nexus-3.18.1-01\bin\nexus.exe.
3.打开浏览器,输入http://127.0.0.1:8081, 如下图:
4.点击右上角的Sign in,第一次登录会让你输入用户名admin,秘密在它提示的一个admin.password文件中,按照它给的路径即可找到.然后会提示你重新设置密码,以后就用你设置的这个密码登录即可.
5.创建仓库.
点击Create repository即可创建一个名为ProjectA-release的发布版本的仓库, 如果想创建快照版本的仓库, 在第6步,选择Snapshot即可.
我这里创建完两个仓库后,开始在androidStudio中做配置
2.在工程目录下的build.gradle文件中配置
分别在buildscript - repositories节点下,和allprojects - repositories配置maven
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral() //这个也是我们经常用到的一个仓库
//开始配置我们自己的私服仓库,分别是release和snapshot
//这只是为gradle的构建添加的仓库,还需要为java工程添加仓库
maven {
url 'http://127.0.0.1:8081/repository/componentization-releases/'
credentials {
username 'admin'
password 'qwer1234'
}
}
maven {
url 'http://127.0.0.1:8081/repository/componentization-snapshots/'
credentials {
username 'admin'
password 'qwer1234'
}
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'http://127.0.0.1:8081/repository/componentization-releases/'
credentials {
username 'admin'
password 'qwer1234'
}
}
maven {
url 'http://127.0.0.1:8081/repository/componentization-snapshots/'
credentials {
username 'admin'
password 'qwer1234'
}
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
在工程目录的gradle.properties文件中做配置几个上传需要的变量
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# 配置上传路径
NEXUS_REPOSITORY_URL=http://127.0.0.1:8081/repository/componentization-snapshots/
# 公司域名倒置+项目类型. eg:com.alibaba.android
POM_GROUPID=com.app.android
# 库类型,打包类型,java:jar Android:aar
POM_PACKAGING=aar
# 用户名
NEXUS_USERNAME=admin
# 密码
NEXUS_PASSWORD=qwer1234
在创建的lib module中的build.gradle文件中配置上传参数
比如,新建的network库,
apply plugin: 'com.android.library'
apply plugin: 'maven' //1.引入maven插件
//2.定义几个变量
def pomName = this.getName()
def pomVersion = '1.0.0-SNAPSHOT'
def pomDescription = 'this network library for all projects'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
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'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
//编写上传所需的配置参数
uploadArchives {
repositories { //仓库信息
mavenDeployer { //maven部署参数
//NEXUS_REPOSITORY_URL,NEXUS_USERNAME,NEXUS_PASSWORD已经在项目目录的gradle.properties中定义
repository(url: NEXUS_REPOSITORY_URL) { //仓库, url
//用户名和密码
authentication (userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
pom.project {
name pomName
version pomVersion
description pomDescription
artifactId pomVersion
groupId POM_GROUPID
packaging POM_PACKAGING
}
}
}
}
同步下项目后,在gradle栏目里可以点击上传network库
未完待续...