在參考郭霖大神的文章 再見JCenter果元,將你的開源庫發(fā)布到MavenCentral上吧 發(fā)布項(xiàng)目到Maven時(shí)候出現(xiàn)一點(diǎn)問題,在此記錄下:
發(fā)布步驟按照上文進(jìn)行就可以了,在點(diǎn)擊pulish發(fā)布時(shí)時(shí)候出現(xiàn)幾點(diǎn)問題:
1.No compatible plugin found in project for publishing
提示發(fā)布時(shí)沒有找到兼容的插件
出現(xiàn)這個(gè)問題時(shí),解決方法可能有以下幾種:
- 需要將項(xiàng)目根目錄下
build.gradle
中apply plugin: "com.vanniktech.maven.publish"
這一行移動(dòng)到app下的build.gradle
- 需要將
app
模塊下的build.gradle
中的apply plugin: 'com.android.application
修改為apply plugin: 'com.android.library'
- 刪除
app
模塊下defaultConfig'
的applicationId
2.點(diǎn)擊publish時(shí)提示找不到匹配的GROUP,提示404
- 需要將
gradle.properties
中GROUP=xxx
修改成與sonatype
上的Group ID一致,要注意大小寫有區(qū)分,
在https://s01.oss.sonatype.org的Staging Profiles中Name這一列也可以看到對(duì)應(yīng)的GROUP名稱
在此貼出項(xiàng)目中的完整代碼:
項(xiàng)目根目錄的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}
app目錄下的build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
kotlinOptions {
jvmTarget = 1.8
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-rc03'
implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.1.0'
}
apply plugin: "com.vanniktech.maven.publish"
gradle.properties
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
GROUP=com.guolindev.glance
POM_ARTIFACT_ID=glance
VERSION_NAME=1.0.0
POM_NAME=Glance
POM_DESCRIPTION=A simple and handy Android database debugging library.
POM_INCEPTION_YEAR=2020
POM_URL=https://github.com/guolindev/Glance/
POM_SCM_URL=https://github.com/guolindev/Glance/
POM_SCM_CONNECTION=scm:git:git://github.com/guolindev/Glance.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/guolindev/Glance.git
POM_DEVELOPER_ID=guolindev
POM_DEVELOPER_NAME=Lin Guo
POM_DEVELOPER_URL=https://github.com/guolindev/
signing.keyId=密鑰ID的后8位
signing.password=密鑰密碼
signing.secretKeyRingFile=私鑰文件路徑
mavenCentralUsername=Sonatype賬號(hào)
mavenCentralPassword=Sonatype密碼
systemProp.org.gradle.internal.publish.checksums.insecure=true