一顽铸、打包配置
1迷守、編輯腳本
在需要打包的module下創(chuàng)建
publish.gradle
apply plugin: 'maven-publish'
task generateSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}
afterEvaluate {
publishing {
publications {
Production(MavenPublication) {
// Applies the component for the release build variant.
from components.release
groupId = GROUP_ID
artifactId = ARTIFACT_ID
version = VERSION
// 上傳source遭笋,這樣使用放可以看到方法注釋
artifact generateSourcesJar
}
}
repositories {
// 定義一個(gè) maven 倉庫
maven {
url = VERSION.endsWith('SNAPSHOT') ? SNAPSHOT_URL : RELEASE_URL
// 倉庫用戶名密碼
credentials {
username = USER_NAME
password = PASSWORD
}
// 允許通過不安全的HTTP連接與倉庫通信
allowInsecureProtocol(true)
}
}
}
}
gradle.properties(配置打包腳本中依賴的資源)
RELEASE_URL=http://120.66.66.66:6666/repository/maven-releases/
SNAPSHOT_URL=http://120.66.66.66:6666/repository/maven-snapshots/
GROUP_ID=com.test.library
ARTIFACT_ID=library
# 在nexus配置的用戶名
USER_NAME=userName
# 在nexus配置的用戶密碼
PASSWORD=password
# 版本號(hào)
VERSION=1.0.1-SNAPSHOT
2、其他配置
- 在需要打包的module下的build.gradle中配置
apply from : "publish.gradle"
3而姐、執(zhí)行打包
在Android studio的Terminal中執(zhí)行命令
./gradlew publish
二膘融、使用配置
- 項(xiàng)目根目錄下的build.gradle添加依賴倉庫
maven {
// maven倉庫地址
url 'http://120.66.66.66:6666/repository/maven-public/'
// 允許使用http訪問的maven倉庫芙粱,如果是https則不用配置
allowInsecureProtocol = true
}
- module下的build.gradle中添加依賴
// com.test.library 是groupId
// library 是artifactId
// 1.0.1-SNAPSHOT 是版本號(hào)
implementation 'com.test.library:library:1.0.1-SNAPSHOT'
三、報(bào)錯(cuò)集合
does not allow updating artifact
- 報(bào)錯(cuò)信息
Artifact updating: Repository ='releases:Releases' does not allow updating artifact='/com/github/120011676/vine/maven-metadata.xml.sha256'
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
- 報(bào)錯(cuò)信息
Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
- 解決方案
在項(xiàng)目根目錄的gradle.properties中配置
# 指定Gradle依賴的JAVA版本
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home