Library發(fā)布到私服Nexus倉(cāng)庫(kù)
1.?配置Nexus倉(cāng)庫(kù)信息:在項(xiàng)目的根目錄的build.gradle.kts文件中配置Nexus倉(cāng)庫(kù)的信息械哟。
2.?添加發(fā)布插件:在你的Library模塊的build.gradle.kts文件中應(yīng)用maven-publish插件。
3.?配置發(fā)布任務(wù):在同一個(gè)build.gradle.kts文件中锨咙,配置發(fā)布任務(wù)披坏,包括groupId谓娃、artifactId梅尤、version等信息,以及倉(cāng)庫(kù)的url和憑證
// 在項(xiàng)目根目錄的 build.gradle.kts 中配置倉(cāng)庫(kù)信息
allprojects {
? ? repositories {
? ? ? ? maven {
? ? ? ? ? ? url = uri("http://your-nexus-repository-url/repository/maven-releases/")
? ? ? ? ? ? credentials {
? ? ? ? ? ? ? ? username = "your-nexus-username"
? ? ? ? ? ? ? ? password = "your-nexus-password"
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
// 在你的Library模塊的 build.gradle.kts 中
plugins {
? ? `maven-publish`
}
publishing {
? ? publications {
? ? ? ? create<MavenPublication>("release") {
? ? ? ? ? ? groupId = "com.example"
? ? ? ? ? ? artifactId = "your-library-name"
? ? ? ? ? ? version = "1.0.0"
? ? ? ? ? ? from(components["release"])
? ? ? ? }
? ? }
? ? repositories {
? ? ? ? maven {
? ? ? ? ? ? name = "Nexus"
? ? ? ? ? ? url = uri("http://your-nexus-repository-url/repository/maven-releases/")
? ? ? ? ? ? credentials {
? ? ? ? ? ? ? ? username = "your-nexus-username"
? ? ? ? ? ? ? ? password = "your-nexus-password"
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
4.?發(fā)布Library:配置完成后赔硫,你可以通過(guò)執(zhí)行發(fā)布任務(wù)將你的Library上傳到Nexus倉(cāng)庫(kù)炒俱。在Android?Studio的Terminal中運(yùn)行以下命令:
./gradlew publish
5.?在其他項(xiàng)目中使用該Library:在其他項(xiàng)目的build.gradle.kts文件中添加Nexus倉(cāng)庫(kù)的地址,并添加對(duì)你的Library的依賴。
repositories {
? ? maven {
? ? ? ? url = uri("http://your-nexus-repository-url/repository/maven-releases/")
? ? }
}
dependencies {
? ? implementation("com.example:your-library-name:1.0.0")
}
repositories?{
????maven?{
????????url?=?uri("http://your-nexus-repository-url/repository/maven-releases/")
????}
}
dependencies?{
????implementation("com.example:your-library-name:1.0.0")
}
確保你的Nexus倉(cāng)庫(kù)地址权悟、用戶名砸王、密碼、groupId峦阁、artifactId和版本號(hào)等信息是正確的谦铃。這樣,你就可以在Android?Studio中使用Kotlin?DSL將Library發(fā)布到私服Nexus倉(cāng)庫(kù)拇派,并在其他項(xiàng)目中使用它了荷辕。