需求:
最近在學(xué)習(xí)組件化窟哺,自己嘗試著使用nexus搭建本地倉庫歼秽,上傳自己的aar包到倉庫
上傳aar包代碼
maven_push.gradle,單獨(dú)保存到一個(gè)gradle文件中筒繁,方便引用
apply plugin: 'maven'
def maven_url = "http://127.0.0.1:8081/repository/debug/"
def m_Username = "admin"
def m_Password = "admin123"
def m_Name = "myName"
def m_Version = "1.0.1"
def m_GroupId = "com.test"
def m_Description = ""
def m_ArtifactId = "mylib"
def m_Type = "aar"
/**
* 生成代碼的文檔窖贤,沒有這個(gè)拜效,引用的包中會(huì)沒有代碼中的文檔
*/
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
archives androidJavadocsJar
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: maven_url) {
authentication(userName: m_Username, password: m_Password)
}
pom.project {
name m_Name
version m_Version
artifactId m_ArtifactId
groupId m_GroupId
packaging m_Type
description m_Description
}
}
}
}
在Module工程中的build.gradle中引用maven_push.gradle文件
apply from: './maven_push.gradle'
這句話不要寫在最后鲫构,寫在dependencies節(jié)點(diǎn)前就行,因?yàn)槲野l(fā)現(xiàn)寫在最后上傳的時(shí)候奋救,會(huì)出現(xiàn)第三方包解析錯(cuò)誤
補(bǔ)充
錯(cuò)誤: 編碼GBK的不可映射字符
在根build.gradle中的allprojects節(jié)點(diǎn)下增加以下代碼,基本就可以解決生成javadoc時(shí)的錯(cuò)誤
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
引用自己的包
在根build.gradle中的allprojects節(jié)點(diǎn)下的repositories節(jié)點(diǎn)中增加以下節(jié)點(diǎn)
maven {
url "http://127.0.0.1:8081/repository/debug/"
}