之前下載的安裝包,現(xiàn)在直接拿來用.
下載地址:https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.18.1-01-win64.zip
1.安裝Nexus并創(chuàng)建倉庫
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, 如下圖:
image.png
4.點(diǎn)擊右上角的Sign in,第一次登錄會(huì)讓你輸入用戶名admin,秘密在它提示的一個(gè)admin.password文件中,按照它給的路徑即可找到.然后會(huì)提示你重新設(shè)置密碼,以后就用你設(shè)置的這個(gè)密碼登錄即可.
5.創(chuàng)建倉庫.
image.png
image.png
image.png
點(diǎn)擊Create repository即可創(chuàng)建一個(gè)名為ProjectA-release的發(fā)布版本的倉庫, 如果想創(chuàng)建快照版本的倉庫, 在第6步,選擇Snapshot即可.
image.png
image.png
我這里創(chuàng)建完兩個(gè)倉庫后,開始在androidStudio中做配置
2.在工程目錄下的build.gradle文件中配置
分別在buildscript - repositories節(jié)點(diǎn)下,和allprojects - repositories配置maven
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral() //這個(gè)也是我們經(jīng)常用到的一個(gè)倉庫
//開始配置我們自己的私服倉庫,分別是release和snapshot
//這只是為gradle的構(gòu)建添加的倉庫,還需要為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文件中做配置幾個(gè)上傳需要的變量
# 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/
# 公司域名倒置+項(xiàng)目類型. eg:com.alibaba.android
POM_GROUPID=com.app.android
# 庫類型,打包類型,java:jar Android:aar
POM_PACKAGING=aar
# 用戶名
NEXUS_USERNAME=admin
# 密碼
NEXUS_PASSWORD=qwer1234
在創(chuàng)建的lib module中的build.gradle文件中配置上傳參數(shù)
比如,新建的network庫,
apply plugin: 'com.android.library'
apply plugin: 'maven' //1.引入maven插件
//2.定義幾個(gè)變量
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'
}
//編寫上傳所需的配置參數(shù)
uploadArchives {
repositories { //倉庫信息
mavenDeployer { //maven部署參數(shù)
//NEXUS_REPOSITORY_URL,NEXUS_USERNAME,NEXUS_PASSWORD已經(jīng)在項(xiàng)目目錄的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
}
}
}
}
同步下項(xiàng)目后,在gradle欄目里可以點(diǎn)擊上傳network庫
image.png
未完待續(xù)...